UIButton标题不显示
我刚刚开始在Swift中开发。
我dynamic创build了一个UIButton并将其添加到View中。 我的问题是视图不显示button。
我的代码:
var button:UIButton = UIButton(); button.frame = CGRect(x: 100, y: 250, width: 100, height: 50); button.setTitle("Midhun", forState: UIControlState.Normal); self.view.addSubview(button);
然后我将图像添加到button,然后显示:
button.setImage(UIImage(named: "step_first.jpg"), forState: UIControlState.Normal);
我无法弄清楚发生了什么事。 请帮忙
其实我想清楚了这个问题
在Swift中, UIButton
的标题是白色的。
我改变了父视图的背景颜色,现在显示。
self.view.backgroundColor = UIColor.blackColor();
对我来说,问题是我没有使用setter方法。
我在做notificationsButton.titleLabel?.text = "x"
而不是notificationsButton.setTitle("x", forState: UIControlState.Normal)
如果你的子类UIButton并重写它的layoutSubviews()
,请确保你调用super.layoutSubviews()
里面