如何使用swift中的函数输入连接变量名

时间:2018-03-14 02:05:55

标签: swift

@IBAction func buttonPressed(_ sender: UIButton) {
    if sender.tag == 1{
        updateUI(storyNumber: 3)
    }else if sender.tag == 2 {
        updateUI(storyNumber: 2)
    }  
}

func updateUI(storyNumber: Int ){
    storyTextView.text = story + (storyNumber)
    topButton.setTitle(answer +(storeyNumber)+ a, for: .normal)
    bottomButton.setTitle(answer +(storeyNumber)+ b, for: .normal)
}

我想知道如何在函数输入上更改变量名称?

1 个答案:

答案 0 :(得分:0)

喜欢这个

func updateUI(storyNumber: Int ){
    storyTextView.text = story + "\(storyNumber)"
    topButton.setTitle(answer + "\(storyNumber)" + a, for: .normal)
    bottomButton.setTitle(answer + "\(storyNumber)" + b, for: .normal)
}

如果a和b不是字符串那么

func updateUI(storyNumber: Int ){
        storyTextView.text = story + "\(storyNumber)"
        topButton.setTitle(answer + " \(storyNumber) " + "\(a)", for: .normal)
        bottomButton.setTitle(answer + " \(storyNumber) " + "\(b)", for: .normal)
    }
Also you can add spaced too...
相关问题