【发布时间】:2016-06-02 12:28:37
【问题描述】:
我的标签栏控制器中有一个视图,我想在其中显示一个按钮。我根据条件以编程方式创建此按钮,因此我使用以下代码但没有出现任何内容:
override func viewDidLoad() {
super.viewDidLoad()
if !Settings.getIsConnected() {
notConnected()
}
}
func notConnected() {
let connectBtn = UIButton(frame: CGRect(x: self.view.center.x, y: self.view.center.y, width: 200, height: 45))
connectBtn.setTitle("Connect", forState: .Normal)
connectBtn.addTarget(self, action:#selector(self.pressedConnect(_:)), forControlEvents: .TouchUpInside)
self.view.addSubview(connectBtn)
print("Button created")
}
func pressedConnect(sender: UIButton!) {
}
我对自己做错了什么一无所知。有人有建议吗?因为它确实会打印出“Button created”,所以它肯定会在 noConnected() 方法中运行代码。
【问题讨论】:
-
尝试为您的 UIButton 添加背景颜色,并为其标题添加色调
-
谢谢,这就是问题所在!不知何故,标题和按钮都是白色的
-
我最近看到一个类似的问题,我认为这是我们以编程方式创建UIButton时的默认颜色