dimanche 10 mai 2015

How to set multiple variables in a FOR loop?

I'm programming in Swift and I'd like to set up a couple of variables in a single loop. These are UIButtons and they all require the same settings. However I don't know how to refer to these variables using "i". This is what I tried:

var gg1:UIButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton
var gg2:UIButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton
var gg3:UIButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton

//further in the code
for i in 1...3 {
    gg(i).layer.anchorPoint.x = 0
    gg(i).titleLabel?.font = UIFont(name: "Arial", size: 20*rightFontSize)
    gg(i).setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
    gg(i).sizeToFit()
    gg(i).center = CGPointMake(w/20,11*h/10)
    scrollView.addSubview(gg(i))
}

Aucun commentaire:

Enregistrer un commentaire