如何更改Swift Xcode 6中的button文本?
这是我想要做的。 如果你曾经玩过Halo或CoD,那么你会知道你可以改变武器装载的名字。
我正在做的是让你可以使用文本字段来改变你的装载名称。 这里有个问题,load-out菜单中的load-out名字是一个button(用于select和查看关于这个load-out的信息),我可以这样写:
@IBAction func renameClassButton(sender: AnyObject) { classTopButton.text = "\(classTopTextField)" } 除了[classTopButton]是一个不允许'.text'后缀的button
你可以做:
 button.setTitle("my text here", forState: .Normal) 
Swift 3:
 button.setTitle("my text here", for: .normal) 
在Xcode 8中 – Swift 3 :
 button.setTitle( "entertext" , for: .normal ) 
现在是这样的快3,
  let button = (sender as AnyObject) button.setTitle("Your text", for: .normal) 
(variables的常量声明是不必要的,只要确保你使用这个button的发送者):
  (sender as AnyObject).setTitle("Your text", for: .normal) 
记住这是在你的button的IBAction中使用的。
您可以使用发件人参数
  @IBAction func TickToeButtonClick(sender: AnyObject) { sender.setTitle("my text here", forState: .Normal) } 
 请注意,如果您使用的是NSButton,则不会有setTitle func,而是一个属性。 
 @IBOutlet weak var classToButton: NSButton! . . . classToButton.title = "Some Text" 
迅速4工作以及3
 libero.setTitle("---", for: .normal) 
libero是一个uibutton