2012-04-05 5 views
6

테두리 (윤곽선)에 다른 색상의 텍스트를 표시하고 싶습니다. 은 내가텍스트 글꼴을 어떻게 요약 할 수 있습니까?

[text drawAtPoint:CGPointMake(0,30) withFont:[UIFont fontWithName:@"Helvetica-Bold" size:(3 * MKRoadWidthAtZoomScale(zoomScale))] 

내가 표시 윤곽 할 텍스트를 필요 제외하고 잘 작동 사용 MapOverlayView에 텍스트를 표시하는 데 노력하고있어.

답변

8

그래, CGContextSetDrawingMode(CGContextRef, CGTextDrawingMode)의 도움으로 윤곽선이 표시된 텍스트를 표시 할 수 있습니다.하지만 모양이 좋게하려면 숫자와 색상을 조정해야 할 수 있습니다.

kCGTextFillStroke를 사용하는 것이 논리적 인 것처럼 보이지만 획이 채우기를 압도적으로 만들 수 있습니다. 스트로크 한 다음 아래 블록에서와 같이 채우면 읽을 수있는 텍스트 뒤에 눈에 띄는 윤곽이 나타납니다.

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGPoint point = CGPointMake(0,30); 
CGFloat fontSize = (3 * MKRoadWidthAtZoomScale(zoomScale)); 
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize]; 

// Draw outlined text. 
CGContextSetTextDrawingMode(context, kCGTextStroke); 
// Make the thickness of the outline a function of the font size in use. 
CGContextSetLineWidth(context, fontSize/18); 
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]); 
[text drawAtPoint:point withFont:font]; 

// Draw filled text. This will make sure it's clearly readable, while leaving some outline behind it. 
CGContextSetTextDrawingMode(context, kCGTextFill); 
CGContextSetFillColorWithColor(context, [[UIColor blueColor] CGColor]); 
[text drawAtPoint:point withFont:font]; 
+0

많은 감사합니다 !! : 나는 다음 코드로 작동시킬 수 있었다 – user836026

+2

제 경우에는 작동하지 않습니다. 동일한 단계를 밟았습니다. –

0

drawAtPoint:withFont:이 (가) 더 이상 지원되지 않을 수 있습니다. ... 그것은 좋은 일

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGFloat fontSize = 18.0; 
CGPoint point = CGPointMake(0, 0); 

UIFont *font = [UIFont fontWithName:@"Arial-BoldMT" size:fontSize]; 
UIColor *outline = [UIColor whiteColor]; 
UIColor *fill = [UIColor blackColor]; 

NSDictionary *labelAttr = @{NSForegroundColorAttributeName:outline, NSFontAttributeName:font}; 

CGContextSetTextDrawingMode(context, kCGTextStroke); 
CGContextSetLineWidth(context, 2.0); 
[text drawAtPoint:point withAttributes:labelAttr]; 

CGContextSetTextDrawingMode(context, kCGTextFill); 
CGContextSetLineWidth(context, 2.0); 
labelAttr = @{NSForegroundColorAttributeName:fill, NSFontAttributeName:font}; 
[text drawAtPoint:point withAttributes:labelAttr]; 
관련 문제