How to control shadow spread and blur?

前端 未结 8 1216
终归单人心
终归单人心 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条回答
  •  猫巷女王i
    2020-12-07 07:26

    My solution based on this post replies: (Swift 3)

    let shadowPath = UIBezierPath(rect: CGRect(x: -1,
                                               y: -2,
                                               width: target.frame.width + 2,
                                               height: target.frame.height + 2))
    
    target.layer.shadowColor = UIColor(hexString: shadowColor).cgColor
    target.layer.shadowOffset = CGSize(width: CGFloat(shadowOffsetX), height: CGFloat(shadowOffsetY))
    target.layer.masksToBounds = false
    target.layer.shadowOpacity = Float(shadowOpacity)
    target.layer.shadowPath = shadowPath.cgPath
    

提交回复
热议问题