How to control shadow spread and blur?

前端 未结 8 1222
终归单人心
终归单人心 2020-12-07 06:51

I have designed UI elements in sketch, and one of them has a shadow with blur 1 and spread 0. I looked at the doc for the views layer property and layer doesnt have anything

8条回答
  •  难免孤独
    2020-12-07 07:29

    This code worked very well for me:

    yourView.layer.shadowOpacity = 0.2 // opacity, 20%
    yourView.layer.shadowColor = UIColor.black.cgColor
    yourView.layer.shadowRadius = 2 // HALF of blur
    yourView.layer.shadowOffset = CGSize(width: 0, height: 2) // Spread x, y
    yourView.layer.masksToBounds = false
    

提交回复
热议问题