【发布时间】:2019-03-13 22:03:54
【问题描述】:
我在屏幕左侧添加了UIButton。我是这样添加的:
let screenSize: CGRect = UIScreen.main.bounds
let menuButtonSize: CGSize = CGSize(width: 44, height: 44)
func confiureCloseButton() {
let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: menuButtonSize))
button.setImage(UIImage(named: "icon_close"), for: UIControl.State.normal)
button.center = CGPoint(x: 50, y: 61)
button.layer.zPosition = 1
button.addTarget(self, action: #selector(closeButtonAction), for: .touchUpInside)
self.view.addSubview(button)
}
如何在右侧添加另一个按钮?
【问题讨论】:
-
方法相同,但
origin.x值不同。 -
@rmaddy -
origin: CGPoint.zero是 0,0。右侧怎么做? -
将第一个
0更改为所需的号码,以便在您想要的位置。更好的是,使用约束。 -
@rmaddy 如何编辑第一个 0?我应该从
CGPoint.zero更改为CGPoint(x: screenSize.width-44, y: 0)吗? -
使用约束。比编码帧要好得多。