小编j.k*_*ssa的帖子

访问UIColor扩展的成员时出错

我想将自定义颜色移动到UIColor的扩展名:

extension UIColor {
    static var nonSelectedTabColor: UIColor {
        return UIColor(white: 0.682, alpha: 1) // #AEAEAE
    }
}
Run Code Online (Sandbox Code Playgroud)

但是在尝试访问它时,它导致了我一个错误:

private static let defaultBorderColor = .nonSelectedTabColor
Run Code Online (Sandbox Code Playgroud)

Reference to member 'nonSelectedTabColor' cannot be resolved without a contextual type

这是什么问题?我怎样才能解决这个问题?

uicolor swift swift-extensions

3
推荐指数
1
解决办法
1806
查看次数

UIButton标签文本的垂直对齐方式,加号(+)和减号(-)

我有一个带有标签文本“ +”和“-”的圆形按钮。垂直对齐不正确。

我已经在做

button.contentVerticalAlignment = UIControlContentVerticalAlignment.center
Run Code Online (Sandbox Code Playgroud)

请帮助将其与中心对齐(垂直)。

文本对齐方式不正确的按钮

vertical-alignment uibutton swift

2
推荐指数
1
解决办法
388
查看次数

以编程方式对 UIButton 进行 1:1 宽度:高度约束

如何在 swift 中以编程方式将 UIButton 上的宽高比约束设置为 1:1 的宽:高比?此图像在 Interface Builder 中显示了我想通过代码实现的目标。

我在 Interface Builder 中的要求

aspect-ratio ios autolayout swift

1
推荐指数
1
解决办法
2512
查看次数