1、最简单的方式(最简单的效果)
UILabel只需要设置shadowOffset和shadowColor两个属性即可
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
label.text = @"文字";
label.shadowOffset = CGSizeMake(1, 1);
label.shadowColor = [UIColor redColor];
[self.view addSubview:label];
2、NSAttributedString
自定义一个view,重写drawRect:方法绘制文本
- (void)drawRect:(CGRect)rect{
NSShadow *shadow = [[NSShadow alloc]init];
shadow.shadowBlurRadius = 1.0;
shadow.shadowOffset = CGSizeMake(1, 1);
shadow.shadowColor = [UIColor redColor];
NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:16.f],
NSForegroundColorAttributeName: [UIColor cyanColor],
NSShadowAttributeName : shadow,//设置阴影属性
NSVerticalGlyphFormAttributeName: @(0)
};
//_text 要绘制的文本
[_text drawInRect:self.bounds withAttributes:dict];
}