您是否嘗試過使用kCGTextFillStroke
?這可能很容易。要使用它,只是覆蓋drawTextInRect
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 1);
CGContextSetLineJoin(c, kCGLineJoinRound);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect];
self.shadowOffset = shadowOffset;
}
編輯:這個問題的答案也出現在這個問題的前世:How do I make UILabel display outlined text?
的
可能重複(HTTP [我如何的UILabel顯示概述文本?]:/ /stackoverflow.com/questions/1103148/how-do-i-make-uilabel-display-outlined-text) – PengOne 2011-06-10 17:13:10