1、使用NSAttributedString
NSAttributedString *aStr = [[NSAttributedString alloc] initWithString:@"邪魔退散" attributes:@{NSStrokeWidthAttributeName:@2, NSStrokeColorAttributeName:[UIColor orangeColor]}];
self.demoLabel.attributedText = aStr;
這樣的效果不太好看:
2读第、使用CoreGraphics
新建一個(gè)繼承自UILabel的類曙博,重寫- (void)drawRect:(CGRect)rect方法
- (void)drawRect:(CGRect)rect {
? ? ?CGContextRef context = UIGraphicsGetCurrentContext();
? ? ?CGContextSetLineWidth(context, 2.5);
? ? ?CGContextSetLineJoin(context, kCGLineJoinRound);
? ? ?CGContextSetTextDrawingMode(context, kCGTextStroke);
? ? ?self.textColor = [UIColor orangeColor];
? ? ?//橙色空心字
? ? ?[super drawTextInRect:rect];
? ? ?CGContextSetTextDrawingMode(context, kCGTextFill);
? ? ?self.textColor = [UIColor whiteColor];
? ? ?//白色實(shí)心字
? ? ?[super drawTextInRect:rect];
}
先畫一個(gè)空心字,然后在畫一個(gè)實(shí)心字卦方。兩個(gè)字放一起產(chǎn)生的效果羊瘩,好處就是可以自己定字體的粗細(xì):
人生中第一個(gè)筆記結(jié)束------------------------------------------------END