这是我用来设置按钮图像的当前代码。按钮设置为故事板的出口。
userPictureButton.sd_setBackgroundImage(with: URL(string: currentUserData.photoURL), for: .normal)
userPictureButton.layer.cornerRadius = userPictureButton.frame.size.width / 2
userPictureButton.clipsToBounds = true
当
clipsToBounds = true
时,向该按钮添加阴影的所有方法似乎都失败了。当我有剪辑到边界,我可以看到一个阴影,但不再有一个圆形按钮。有人知道解决办法吗?
最佳答案
试试这个:
将UIButton
嵌入UIView
中,然后根据以下代码应用shadow
和corner radius
:
button.layer.cornerRadius = 10.0
button.clipsToBounds = true
containerView.clipsToBounds = false
containerView.layer.cornerRadius = 10.0
containerView.layer.shadowOffset = CGSize(width: 2, height: 2)
containerView.layer.shadowRadius = 3.0
containerView.layer.shadowColor = UIColor.black.cgColor
containerView.layer.shadowOpacity = 1.0
根据你的要求给出数值。
关于ios - 向圆形按钮添加阴影,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45645593/