美文网首页
字体阴影效果

字体阴影效果

作者: y2015 | 来源:发表于2016-11-30 17:04 被阅读107次
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];
}
以后继续补充

相关文章

网友评论

      本文标题:字体阴影效果

      本文链接:https://www.haomeiwen.com/subject/tumzpttx.html