美文网首页
iOS UIView的圆角加阴影效果的实现

iOS UIView的圆角加阴影效果的实现

作者: LTSimple | 来源:发表于2018-01-06 00:35 被阅读157次

iOS UIView的圆角加阴影效果的实现

我们都知道削圆角一般有两种方式,一种是直接用layer.cornerRadius来设置,我们知道的一般都是下面两行代码一起使用来实现圆角:

self.layer.masksToBounds = true;
self.layer.cornerRadius = 10;

但是只要self.layer.masksToBounds=YES;有这句,投影的效果就出不来。

还有一种性能比较好的圆角设置方式,就是用UIBezierPath来设置,我试过用这个来设置圆角的话,投影一样也出不来。
还有在网上看到了加一层layer的,大体思路就是self.layer来设置圆角,新写一个layer来设置投影,然后把layer放到self.layer上,我试了之后发现没什么效果,而且偏移会很明显的看出来,但不是以投影的方式出现。

    self.backgroundColor = [UIColor whiteColor];
    //self.layer.masksToBounds=YES;这行去掉
    self.layer.cornerRadius = 10;
    self.layer.shadowColor = [UIColor blackColor].CGColor;
    self.layer.shadowOffset = CGSizeMake(2, 5);
    self.layer.shadowOpacity = 0.5;
    self.layer.shadowRadius = 5;

相关文章

网友评论

      本文标题:iOS UIView的圆角加阴影效果的实现

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