iOS UILabel文字添加描边实现

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010960265/article/details/82977553

可以达到文字描一圈黑边的效果:
在这里插入图片描述

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

猜你喜欢

转载自blog.csdn.net/u010960265/article/details/82977553
今日推荐