gpt4 book ai didi

uibutton - shadowPath 不适用于 UIButton

转载 作者:行者123 更新时间:2023-11-28 05:34:44 26 4
gpt4 key购买 nike

我正在创建一个这样的按钮:

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)

之后,我尝试使用我自己的 shadowPath 添加阴影,如下所示:

        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)

我真正的阴影路径要复杂得多。

阴影根本不显示。

可能是什么问题?

最佳答案

问题与贝塞尔曲线路径有关:原点应为 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com