美文网首页
label添加描边

label添加描边

作者: AnnieAri | 来源:发表于2017-06-30 13:47 被阅读0次

新建label类继承UILabel
重写下面方法

- (void)drawTextInRect:(CGRect)rect {
    
    CGSize shadowOffset = self.shadowOffset;
    UIColor *textColor = self.textColor;
    
    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(c, 2);
    CGContextSetLineJoin(c, kCGLineJoinRound);
    
    CGContextSetTextDrawingMode(c, kCGTextStroke);
    self.textColor = [UIColor blackColor];//描边颜色
    [super drawTextInRect:rect];
    
    CGContextSetTextDrawingMode(c, kCGTextFill);
    self.textColor = textColor;//字体内部颜色
    self.shadowOffset = CGSizeMake(0, 0);
    [super drawTextInRect:rect];
    
    self.shadowOffset = shadowOffset;
    
}

相关文章

网友评论

      本文标题:label添加描边

      本文链接:https://www.haomeiwen.com/subject/zxobcxtx.html