通常的添加阴影只能给label添加,但是不能给label的文字添加。这次就来说一下如何给文字添加阴影。废话不说,直接上代码吧,有问题或者更好的建议欢迎评论哦。其实一开始自己也是想写一个category的,但是发现不行,如果有谁有好办法,一定要告诉我哦,谢谢啦!
#import
@interface BorderTextLabel : UILabel
/** 描边宽度*/
@property (nonatomic, assign) CGFloat textBorderWidth;
/** 描边颜色*/
@property (nonatomic, strong) UIColor *textBorderColor;
/** 带阴影的文字*/
@property (nonatomic, strong) NSString *shadowText;
@end
#import "BorderTextLabel.h"
@implementation BorderTextLabel
@synthesize textBorderWidth = _textBorderWidth, textBorderColor = _textBorderColor, shadowText = _shadowText;
- (void)drawTextInRect:(CGRect)rect {
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, sel