2017-08-12 94 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 

根據您的要求提供的值。