samedi 28 février 2015

Define buttonnummer programmatically?

I'm trying to set the title of a button in Swift. The button title and number is random. I have button1..16. Swift doesn't accept 'button' with 'String doesn't have a member named 'setTitle'. How can I make Swift accept this?



var buttonNumber = arc4random_uniform(16) + 1
var targetNumber = arc4random_uniform(20) + 1
var button = "button\(buttonNumber)"
button.setTitle("\(targetNumber)", forState: UIControlState.Normal)




Aucun commentaire:

Enregistrer un commentaire