如何在Swift Xcode 6中更改按钮文本? [英] How to change button text in Swift Xcode 6?

查看:107
本文介绍了如何在Swift Xcode 6中更改按钮文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要做的。如果你曾经玩Halo或CoD,你就会知道你可以更改武器装载的名称。

Here's what I'm trying to do. If you've ever played Halo or CoD, you'd know that you could change the name of a weapon load-out.

我正在做的是制作它这样您就可以使用文本字段更改装载名称。这是问题,加载菜单中的加载名称是一个按钮(用于选择和查看有关该加载的信息),我可以这样写:

What I'm doing is making it so you can change your load-out name using a text field. Here's the problem, the load-out name in the load-out menu is a button (to select and view info about that load-out) and I could just write this:

@IBAction func renameClassButton(sender: AnyObject) {
    classTopButton.text = "\(classTopTextField)"
}

除了[classTopButton]是一个不允许'。text'后缀的按钮

Except it [classTopButton] is a button which doesn't allow the '.text' suffix

推荐答案

你可以这样做:

button.setTitle("my text here", forState: .normal)

Swift 3和4:

Swift 3 and 4:

button.setTitle("my text here", for: .normal)

这篇关于如何在Swift Xcode 6中更改按钮文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆