刚开始觉得这功能很娱乐……
后来想想,任何设计都是有他的道理,有他的原因的,除非特别不合理,我会选择无视。
无论美丑,人家设计出来,作为RD,你就应该能够够给做出来(值不值得做 另说),就算没几天被砍掉,也没辙……
最开始实在这里找到的答案:
http://stackoverflow.com/questions/1103148/how-do-i-make-uilabel-display-outlined-text
看完之后觉得好简单……
如果你只是简单的想加个描边,而不需要为以后做更好的扩展,或者做成公共的Custom Label控件,下面的代码足够你了。
- (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;
}
当然,如果你有更高的追求,更好的封装意识……
用这个:https://github.com/vigorouscoding/KSLabel。
还有这个:https://github.com/MuscleRumble/THLabel
都是很好的Demo。
参考:https://developer.apple.com/library/mac/documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_text/dq_text.html#//apple_ref/doc/uid/TP30001066-CH213-TPXREF101
Use this mode |
---|