UILabel 文字描边

可以达到文字描一圈白边的效果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//继承UILabel以后重载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;
 
}

posted on 2014-07-30 13:53  恒山之阳  阅读(543)  评论(0编辑  收藏  举报

导航