当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS基于 UILabel实现文字添加描边功能

iOS基于 UILabel实现文字添加描边功能

2019年07月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; 
}

总结

以上所述是小编给大家介绍的ios基于 uilabel实现文字添加描边功能,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网