Can't set cornerRadius AND shadow on layer that has an image view stretched to its bounds?

前端 未结 5 682
醉话见心
醉话见心 2020-12-31 03:00

This is stumping me. I have a UIView (call it \"parent\"). The bottommost subview of that view is a UIImageView (call it \"child\"), whose frame occupies the entirety of the

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 03:33

    Normally you have to set clipsToBounds to have rounded corners, but since you want to retain the shadow you have to round the corners of the shadow as well. Have you tried setting the shadow path using a bezier path? Keep clipsToBounds/masksToBounds to the default, NO. Something like:

      [[parent layer] setCornerRadius:6.0f];
      [[parent layer] setShadowPath:
                 [[UIBezierPath bezierPathWithRoundedRect:[parent bounds] 
                       cornerRadius:6.0f] CGPath]];
    

提交回复
热议问题