在Swift中的对话框中以编程方式更改UIBUTTON尺寸
我在Swift IOS中使用自定义按钮UIBUTTON创建对话框。如何编程更改UIBUTTON尺寸。
class SuccessMessageView: UIView, UITextFieldDelegate {
private var buttonConfirm : UIButton = {
let button = UIButton()
button.setTitle("Ok", for: .normal)
button.backgroundColor = UIColor(rgb: PreferenceManager.shared.hasDevice() ? purpleColour : orangeColour)
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 10
button.addTarget(self, action: #selector(confirmFunc), for: .touchDown)
button.translatesAutoresizingMaskIntoConstraints = false
button.widthAnchor.constraint(equalToConstant: 140.0).isActive = true
button.frame.size.width = 140
return button
}
}
I create dialog with custom button UIButton in swift IOS. How can change UIButton size programmatically.
class SuccessMessageView: UIView, UITextFieldDelegate {
private var buttonConfirm : UIButton = {
let button = UIButton()
button.setTitle("Ok", for: .normal)
button.backgroundColor = UIColor(rgb: PreferenceManager.shared.hasDevice() ? purpleColour : orangeColour)
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 10
button.addTarget(self, action: #selector(confirmFunc), for: .touchDown)
button.translatesAutoresizingMaskIntoConstraints = false
button.widthAnchor.constraint(equalToConstant: 140.0).isActive = true
button.frame.size.width = 140
return button
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你能尝试一下吗?只需删除与框架相关的线。
Could you try this? Just remove the frame-related lines.
我找到了设置UIBUTTON宽度和高度的解决方案,就像恒定设置一样。
I found the solution for set UIButton width and height programatically like that set with constant.