gpt4 book ai didi

swift - 以编程方式约束按钮

转载 作者:行者123 更新时间:2023-11-30 10:39:13 24 4
gpt4 key购买 nike

我希望我的按钮保持在 x 轴中心,但我想在 y 轴上调整它。我的按钮是通过编程制作的,但我的注册页面主要是在 Storyboard上构建的。这使得按钮看起来与其他所有东西都不同

 super.viewDidLoad()


button = dropDownBtn.init(frame: CGRect(x:0, y:0, width:0, height: 0))
button.setTitle("BusinessType", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false

self.view.addSubview(button)

PROBLEM !!!!!
//button.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true

//button.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true

button.widthAnchor.constraint(equalToConstant: 200).isActive = true
button.heightAnchor.constraint(equalToConstant: 40).isActive = true
button.self.layer.cornerRadius = 10

button.dropView.dropDownOptions = ["Apparel", "Artist", "Beauty", "Cosmetology", "Fitness", "Resturant","Photography"]

最佳答案

重新注释centerXAnchorcenterYAnchor约束

NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: self.view.centerYAnchor,constant:-200),
button.widthAnchor.constraint(equalToConstant: 200),
button.heightAnchor.constraint(equalToConstant: 40)
])

关于swift - 以编程方式约束按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57227543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com