[IOS 开发] UILabel文字描边

来源:互联网 发布:跳跃网络 帐号注销 编辑:程序博客网 时间:2024/06/02 06:51



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


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


0 0