对于UILabel来说,设置文字的阴影有两种方法
1.直接设置UILabel的shadowColor和shadowOffset属性,但是这种做法有个问题,就是阴影没有模糊的效果,并且无法设置阴影的宽度等等,比较有局限性。
2.通过设置UILabel中的attributedText属性来给文字添加阴影,这样可以添加更多的效果,如下面的代码
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowBlurRadius = 4;//阴影半径,默认值3
shadow.shadowColor = [UIColor colorWithHexString:@"000000" alpha:0.13];//阴影颜色
shadow.shadowOffset = CGSizeMake(1, 5);//阴影偏移量,x向右偏移,y向下偏移,默认是(0,-3)
NSAttributedString * attributedText = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSShadowAttributeName:shadow}];
durationLabel.attributedText = attributedText;