美文网首页
view圆角、阴影

view圆角、阴影

作者: 凨弥 | 来源:发表于2018-10-25 00:39 被阅读0次

项目中用到卡片模式,有阴影效果,记录一下
切角一般用到 layer.masksToBounds = trueUIBezierPath

shadowColor: 阴影颜色
shadowRadius: 阴影切角
shadowOffset: 偏移量 与 shadowRadius配合使用,如shadowRadius = 5 (0,0)代表四边都有阴影,x代表左右偏移,y代表上下偏移
shadowOpacity: 透明度


 let tsView = UIView(frame: CGRect(x: 37, y: 100, width: 300, height: 300))
        tsView.backgroundColor = #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1)
        tsView.layer.cornerRadius = 10
        tsView.layer.shadowColor = #colorLiteral(red: 0, green: 1, blue: 0.8727540374, alpha: 1).cgColor
        tsView.layer.shadowOffset = CGSize(width: 10, height: 10)
        tsView.layer.shadowRadius = 5
        tsView.layer.shadowOpacity = 0.9
        tsView.layer.borderWidth = 0.5
        tsView.layer.borderColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1).cgColor
        view.addSubview(tsView)
QQ20181025-001733@2x.png QQ20181025-001751@2x.png

注意

遇到的坑,masksToBounds 属性设置为 true 是,阴影效果是出不来的
官方说明:

/* When true an implicit mask matching the layer bounds is applied to
     * the layer (including the effects of the `cornerRadius' property). If
     * both `mask' and `masksToBounds' are non-nil the two masks are
     * multiplied to get the actual mask values. Defaults to NO.
     * Animatable. */

目前发现UIImageView显示的图片对于切角不好使!

相关文章

  • 圆角和阴影共存

    圆角和阴影并存: 两个view分别处理圆角和阴影。 处理阴影的view可以是透明的。 圆角如果不用masksToB...

  • iOS设置圆角后阴影不显示

    问题 设计图中View有阴影和圆角,里面填充了四个按钮。同时设置View的圆角和阴影,阴影并不显示。试了很多次,找...

  • ios 阴影与部分圆角并存

    圆角和阴影并存 首先先说阴影和view的全部圆角并存 不考虑性能的情况下 1、在view下面在加一个view设置阴...

  • 给切过圆角的View,加阴影(既切圆角又加阴影)

    给切过圆角的View,加阴影(既切圆角又加阴影)先附上效果图: iOS项目上常常需要给一个View设置圆角的同时再...

  • view圆角、阴影

    项目中用到卡片模式,有阴影效果,记录一下切角一般用到 layer.masksToBounds = true 或 ...

  • view 圆角+阴影

    UIView*view = [[UIViewalloc]init]; view.frame = CGRectM...

  • 2018-09-07

    oc 圆角阴影设置 View.backgroundColor = [UIColor whiteColor]; Vi...

  • iOS view同时加阴影和圆角

    怎么给view加阴影的同时增加圆角: 顺序很重要,先加阴影后加圆角并且不切角;如: UIView *imgView...

  • UIView设置圆角并且设置阴影效果

    最近有一个需求是一个View添加阴影效果,但是这个View是有圆角的 由于圆角回去设置masksToBounds ...

  • iOS 阴影+圆角

    1.圆角 2.阴影 3.圆角加阴影(错误) 解决方法: 创建一个view,设置阴影效果,然后将所需视图添加到vie...

网友评论

      本文标题:view圆角、阴影

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