gpt4 book ai didi

ios - UIButton 宽度的自动布局问题

转载 作者:行者123 更新时间:2023-11-29 05:28:32 25 4
gpt4 key购买 nike

    signUpButton.translatesAutoresizingMaskIntoConstraints = false
signUpButton.widthAnchor.constraint(equalToConstant: 128).isActive = true
signUpButton.heightAnchor.constraint(equalToConstant: 64).isActive = true
signUpButton.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
signUpButton.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
signUpButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
  • NSLayoutConstraint: UIButton:'注册'.width == 128(事件),
  • NSLayoutConstraint:H:|-(0)-[UIButton:'注册'](事件,名称:'|':UIView:),
  • NSLayoutConstraint: UIButton:'注册'.trailing == UIView:.trailing(事件),
  • NSLayoutConstraint:“UIView-Encapsulated-Layout-Width”UIView:.width == 375(事件)

将尝试通过打破约束来恢复NSLayoutConstraint: UIButton:'注册'.width == 128 (事件)>

我想将按钮放在具有一定宽度的前导和尾随 anchor 的中心,但是当我运行代码时,按钮会扩展到这些 anchor 。我怎样才能阻止这种扩张?

最佳答案

由于您似乎希望将按钮在 view 内水平居中,因此您需要替换:

signUpButton.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
signUpButton.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true

与:

signUpButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true

关于ios - UIButton 宽度的自动布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57913799/

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