我正在创建这样一个按钮:
let authorizationButton = UIButton()
let authorizationButtonHeight = 50.0
let authorizationButtonX = 10.0
let authorizationButtonWidth = UIScreen.mainScreen().bounds.size.width - authorizationButtonX * 2
let authorizationButtonY = UIScreen.mainScreen().bounds.size.height - 10.0 - authorizationButtonHeight
authorizationButton.frame = CGRectMake(authorizationButtonX, authorizationButtonY, authorizationButtonWidth, authorizationButtonHeight)
在那之后,我试图用我自己的阴影路径添加一个阴影,如下所示:
authorizationButton.layer.shadowPath = UIBezierPath(rect:CGRectMake(authorizationButton.frame.origin.x, authorizationButton.frame.origin.y,
authorizationButton.frame.size.width, authorizationButton.frame.size.height)).CGPath
authorizationButton.layer.shadowColor = UIColor.blackColor().CGColor
authorizationButton.layer.shadowOpacity = 1.0
authorizationButton.layer.shadowRadius = 3.0
authorizationButton.layer.shadowOffset = CGSizeMake(3.0, 3.0)
我真正的影子之路要复杂得多。
完全不显示阴影。
有什么问题吗?
最佳答案
问题与bezier路径有关:原点应为0,0。
更改代码如下:
authorizationButton.layer.shadowPath = UIBezierPath(rect:
CGRectMake(0,
0,
authorizationButton.frame.size.width,
authorizationButton.frame.size.height)).CGPath
关于uibutton - shadowPath无法与UIButton一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24552638/