现在,我正在使用这段代码:

    donorButton.layer.shadowColor = UIColor.red
    donorButton.layer.shadowOffset = CGSize(width: 0, height: 2)
    donorButton.layer.shadowRadius = 2
    donorButton.layer.shadowOpacity = 1.0


接下来是输出,而我想摆脱文本上的阴影
ios - 如何仅将阴影添加到UIButton边框而不是文本-LMLPHP

最佳答案

我认为,您的问题有2个解决方案。


如果您不关心按钮的背景色,只需将按钮的背景色更改为非透明色即可。

donorButton.backgroundColor = UIColor.white

如果您需要透明的背景。


给您的按钮留空文本。
UILabel放在按钮下方,并为按钮设置相同的约束。
设置label.textAlignment = NSTextAlignment.center



结果

ios - 如何仅将阴影添加到UIButton边框而不是文本-LMLPHP

关于ios - 如何仅将阴影添加到UIButton边框而不是文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49597332/

10-13 03:58