我在Swift中編程,我想在單個循環中設置幾個變量。 這些是UIButtons,它們都需要相同的設置。但我不知道如何使用「我」來引用這些變量。這是我的嘗試:如何在FOR循環中設置多個變量?
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))
}
將它們放在數組中。 – mustafa