您是否尝试过使用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