2017-08-12 115 views
0

这是我用来设置我的其中一个按钮的图像的当前代码。该按钮被设置为故事板的出口。无法为我的圆形按钮添加阴影 - Swift iOS Dev

userPictureButton.sd_setBackgroundImage(with: URL(string: currentUserData.photoURL), for: .normal) 
    userPictureButton.layer.cornerRadius = userPictureButton.frame.size.width/2 
    userPictureButton.clipsToBounds = true 

每个向该按钮添加阴影的方法似乎在剪辑到边界= true时失败。当我有剪辑限制,我可以看到一个影子,但不再有一个圆形的按钮。

任何人都知道解决方案吗?

谢谢。

回答

0

试试这个:

嵌入您UIButtonUIView,然后按照下面的代码应用shadowcorner 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 

根据您的要求提供的值。