【发布时间】:2019-03-03 12:28:58
【问题描述】:
我需要在我的 iPhone 应用程序的底角放置一个圆形按钮。截至目前,对于 iPhone 5,下面的代码很好,但对于其他 iPhone,按钮位于中间。
let button = UIButton(type: .custom)
button.frame = CGRect(x: 260, y: 500, width: 50, height: 50)
button.layer.cornerRadius = 0.5 * button.bounds.size.width
button.clipsToBounds = true
button.setImage(UIImage(named:"dummy.jpg"), for: UIControlState.normal);
button.addTarget(self, action: #selector(bankButtonPressed), for: .touchUpInside)
view.addSubview(button)
那么我如何动态设置按钮名称以使其适合所有 iPhone 型号。 我想要 button.frame = CGRect(x: 260, y: 500, width: 50, height: 50) - 它的 x 和 y 动态设置,以便它始终位于底角。 我附上了屏幕截图,这就是它的外观。
请同样指导。
【问题讨论】:
-
对于其他视图,您是否使用自动布局?如果是,你也应该将它用于按钮,如果不是,你应该对所有视图使用自动布局。
标签: ios swift dynamic uibutton