gpt4 book ai didi

ios - Swift - UIButton 改变宽度

转载 作者:行者123 更新时间:2023-11-28 23:23:04 28 4
gpt4 key购买 nike

我遇到一个问题,UIButton 正在改变如果我在同一个 View 中添加另一个按钮它的宽度。



这是没有第二个按钮的样子:



enter image description here



这就是我将第二个按钮(标题:“Wishlist?”)限制在同一个 view 中时的样子:



enter image description here



这就是我创建圆形图像按钮的方式:



let wishButton: UIButton = {
let v = UIButton()
v.setBackgroundImage(UIImage(named: "wishButton"), for: .normal)
v.translatesAutoresizingMaskIntoConstraints = false
v.addTarget(self, action: #selector(wishButtonTapped), for: .touchUpInside)
v.contentVerticalAlignment = .fill
v.contentHorizontalAlignment = .fill
return v
}()

// constrain wishButton
wishButton.centerXAnchor.constraint(equalTo: popUpView.centerXAnchor).isActive = true
wishButton.centerYAnchor.constraint(equalTo: popUpView.centerYAnchor, constant: 70).isActive = true
wishButton.heightAnchor.constraint(equalToConstant: 72).isActive = true
wishButton.widthAnchor.constraint(equalToConstant: 72).isActive = true

带标题的第二个按钮:

let dropDownButton: dropDownBtn = {
let v = dropDownBtn()
v.setTitle("Wishlist?", for: .normal)
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()

// constrain dropDownButton
dropDownButton.centerXAnchor.constraint(equalTo: popUpView.centerXAnchor).isActive = true
dropDownButton.centerYAnchor.constraint(equalTo: popUpView.centerYAnchor).isActive = true
wishButton.heightAnchor.constraint(equalToConstant: 100).isActive = true
wishButton.widthAnchor.constraint(equalToConstant: 40).isActive = true

最佳答案

你有冲突

wishButton.heightAnchor.constraint(equalToConstant: 72).isActive = true
wishButton.widthAnchor.constraint(equalToConstant: 72).isActive = true

wishButton.heightAnchor.constraint(equalToConstant: 100).isActive = true
wishButton.widthAnchor.constraint(equalToConstant: 40).isActive = true

你可能是说

dropDownButton.heightAnchor.constraint(equalToConstant: 100).isActive = true
dropDownButton.widthAnchor.constraint(equalToConstant: 40).isActive = true

关于ios - Swift - UIButton 改变宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59337981/

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