Creating a shadow for a UIImageView that has rounded corners?

前端 未结 5 1403
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 14:17

I am trying to create an ImageView that has rounded corners and a shadow to give it some depth. I was able to create a shadow for the UIImageView,

5条回答
  •  遥遥无期
    2020-11-27 14:50

    Here is a another solution (tested code) in swift 2.0

    If you set clipsToBounds to true, this will round the corners but prevent the shadow from appearing. So, you can add same size UIView in storyboard behind imageview and we can give shadow to that view

    SWIFT 2.0

    outerView.layer.cornerRadius = 20.0
    outerView.layer.shadowColor = UIColor.blackColor().CGColor
    outerView.layer.shadowOffset = CGSizeMake(0, 2)
    outerView.layer.shadowOpacity = 1
    outerView.backgroundColor = UIColor.whiteColor()
    

提交回复
热议问题