swift NSLocalizedString in else if

时间:2015-04-04 19:22:01

标签: swift button translate nslocalizedstring

我正在研究我的第一个快速应用程序。现在我想用带有NSLocalizedString的BUTTON翻译文本,但我不知道如何用swift编写它。

这是我的else-if函数:

override func viewDidLoad() {
    super.viewDidLoad()
if volumeBool {
    volumeOut.setTitle("SOUND ON", forState: UIControlState.Normal)
} else {
    volumeOut.setTitle("SOUND OFF", forState: UIControlState.Normal)
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

使用

NSLocalizedString("string to translate", comment: "comment for the language file")

所以在viewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()

    if volumeBool {
        volumeOut.setTitle(NSLocalizedString("SOUND ON", comment: "Title for sound on"), forState: UIControlState.Normal)
    } 
    else {
        volumeOut.setTitle(NSLocalizedString("SOUND OFF", comment: "Title for sound off"), forState: UIControlState.Normal)
    }
}