【问题标题】:Why not changed uibutton title programatically in swift?为什么不以编程方式快速更改 uibutton 标题?
【发布时间】:2015-05-20 06:45:13
【问题描述】:

我在屏幕上有一个 UIButton,我想在开始时更改这个标题。 我试过这个:

@IBOutlet weak var addCardCenterBtn: UIButton!
func roundedButton(){
    self.addCardCenterBtn = UIButton.buttonWithType(.Custom) as! UIButton
    self.addCardCenterBtn.layer.cornerRadius = 0.5 * addCardCenterBtn.bounds.size.width
    self.addCardCenterBtn.backgroundColor = UIColor.blackColor()
    self.addCardCenterBtn.setTitle("AS", forState: UIControlState.Normal)
}

override public func viewDidAppear(animated: Bool) {
    roundedButton()
}

但它不起作用,我不知道为什么。在情节提要中,我连接到 viewcontroller 我的按钮。

【问题讨论】:

  • 你可以在我的问题中看到代码
  • 删除此行self.addCardCenterBtn = UIButton.buttonWithType(.Custom) as! UIButton。因为它已经初始化了。
  • @YogeshSuthar 谢谢!但我不知道为什么

标签: ios swift uibutton


【解决方案1】:

删除此行self.addCardCenterBtn = UIButton.buttonWithType(.Custom) as! UIButton

因为它已经初始化了。当您将故事板中的任何控件连接到 ViewController 时,切勿再次对其进行初始化。只需对其进行更改,新的更改就会生效。

【讨论】:

    猜你喜欢
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 2014-11-07
    • 2015-10-15
    • 2017-01-14
    • 2012-09-21
    相关资源
    最近更新 更多