文字描边方法


转载自:http://www.cocoachina.com/bbs/read.php?tid=80152&page=1



搜索到一个强悍的文字描边方法,分享一下   

http://stackoverflow.com/questi*****/1103148/how-do-i-make-uilabel-display-outlined-text
神一般的老外啊


可以达到文字描一圈白边的效果


继承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;

}

你可能感兴趣的:(iPhone)