【发布时间】:2016-06-10 14:44:16
【问题描述】:
这是我的代码
var button = [UIButton?](count:3, repeatedValue: UIButton())
for i in 0...2{
button[i]!.tag = i
button[i]!.frame = CGRectMake(CGFloat(i) *(collectionViewLove?.frame.width)!/3,0,(collectionViewLove?.frame.width)!/3, 30)
button[i]!.setTitle(titleForButtonsOneSelected[i], forState: .Normal)
button[i]!.titleLabel?.adjustsFontSizeToFitWidth = true
button[i]!.layer.borderWidth = 1.0
button[i]!.layer.borderColor = UIColor.blueColor().CGColor
button[i]!.backgroundColor = UIColor.clearColor()
button[i]!.setTitleColor(UIColor.blackColor(), forState: .Normal)
view.addSubview(button[i]!)
}
问题是仅显示添加到视图的最后一个按钮。如何在视图中显示所有按钮对象?
编辑: 我得到的 UIButton 的帧值
(0.0, 0.0, 106.666666666667, 30.0)
(106.666666666667, 0.0, 106.666666666667, 30.0)
(213.333333333333, 0.0, 106.666666666667, 30.0)
【问题讨论】:
-
每次更改按钮框架...特别是 x 和 y
-
我在上面的代码里改了。
-
您的按钮是如何创建的?
-
如您所见,EDIT 中的按钮框架不同。
-
@Eendje var button = [UIButton?](count:3, repeatValue: UIButton())
标签: ios swift uiview uibutton subview