如何循环多的UIButton在迅速
问题描述:
我打算通过使用循环,使我的UIButton架的新位置,但我没有运气,这里是我的代码:如何循环多的UIButton在迅速
override func viewDidLoad() {
super.viewDidLoad()
for (var i = 75 ; i <= 275; ++i) {
let marginLoopButton: CGFloat = 175.0
let widthLoopButton = view.bounds.width - 2 * marginLoopButton
let marginYLoopButton: CGFloat = 295.0
let minimalYLoopButton = view.bounds.maxY - 2 * marginYLoopButton
self.loopButtonTwo.frame = CGRect(x: i, y: minimalYLoopButton, width: widthLoopButton, height: 70)
self.loopButtonTwo.setTitle("Orange", forState: UIControlState.Normal)
self.view.addSubview(self.loopButtonTwo)
}
}
所以第一个按钮的位置会比不同第二个按钮。问题是:self.loopButtonTwo.frame = CGRect(x: i, y: minimalYLoopButton, width: widthLoopButton, height: 70)
当我把i
上x:
Xcode中给我的错误信息:“不能调用初始化类型的CGRect与类型的参数列表(x:INT,Y:CGFloat的,宽度”
以及如何乘在迅速的号码吗?我知道用C,我们只是写for (i = 75 ; i <= 275; +=10){}
,但如何在迅速写?
任何人都可以帮我吗?
答
只投我以CGFloat的。
self.loopButtonTwo.frame = CGRect(x: CGFloat(i), y: minimalYLoopButton, width: widthLoopButton, height: 70)
+0
谢谢你的作品! @jason nam – hdjkshdak
+0
请选择我的答案,这对我非常有用:) –
是使用视图自动布局? – *foe
我认为这段代码不会做你想做的事情,你试图让按钮动起来吗?如果是这种情况,你需要使用'UIView.animate ...'方法 – Fonix
@*foe根本不是 – hdjkshdak