【发布时间】:2016-10-02 09:56:33
【问题描述】:
我正在使用以下代码在扩展程序中创建一个 uibutton:
extension UIButton {
func customButton(_ title: String, selector: Selector) -> UIButton{
let button = UIButton()
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.black.cgColor
button.titleLabel!.font = UIFont.systemFont(ofSize: 16)
button.setTitle(title, for: UIControlState())
button.setTitleColor(UIColor.black, for: UIControlState())
button.setTitleColor(UIColor(r: 220, g: 220, b:220), for: .highlighted)
button.titleEdgeInsets = UIEdgeInsetsMake(8, 8, 8, 8)
button.layer.cornerRadius = 5
button.sizeToFit()
button.addTarget(self, action: selector, for: .touchUpInside)
button.frame = CGRect(x: 0, y: 0, width: 80, height: 30)
button.alpha = 0.4
return button
}
}
问题是我将此按钮用作 UIBarButtonItem 中的自定义视图:
UIBarButtonItem(customView: self.customButton!)
该按钮将 alpha 设置为 0.4,但该按钮仍以完整的 alpha 显示!
我什至尝试在调用 customButton 方法后在类中切换它,但它根本不起作用。
我试图让按钮在第一次打开时看起来被禁用,并且不可能让那个 alpha 工作。
【问题讨论】:
标签: swift uibarbuttonitem