我目前正在与一个垂直
   
    UIStackView
   
   其中每个视图都有一个
   
    UILabel
   
   
    UIButton
   
   将显示在右侧。标签的前导约束应该不同于按钮的尾部约束,并且整个视图应该占据屏幕的宽度。这个
   
    alignment
   
   因为stackview是
   
    fill
   
   
    fillEqually
   
   .
  
  
   
    
   
  
  
  
  
   我遇到的问题是,自动布局似乎没有遵守我试图为按钮设置的尾部约束
   
   
   
    20
   
   .  我试过了
   
    center
   
   ,
   
    leading
   
   ,和
   
    trailing
   
  
  
   我的约束条件(
   
    radioButton
   
   尾部约束常量设置为
   
    0
   
  
  private func sharedInitialization() {
    translatesAutoresizingMaskIntoConstraints = false
    textLabel.translatesAutoresizingMaskIntoConstraints = false
    radioButton.translatesAutoresizingMaskIntoConstraints = false
    addSubview(textLabel)
    addSubview(radioButton)
    NSLayoutConstraint.activate([
        radioButton.widthAnchor.constraint(equalToConstant: 30),
        radioButton.heightAnchor.constraint(equalToConstant: 30),
        radioButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0),
        radioButton.centerYAnchor.constraint(equalTo: centerYAnchor),
        textLabel.trailingAnchor.constraint(equalTo: radioButton.leadingAnchor, constant: -10),
        textLabel.topAnchor.constraint(equalTo: topAnchor, constant: 22),
        textLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10),
        bottomAnchor.constraint(equalTo: textLabel.bottomAnchor, constant: 22)])
}
  
   可视化调试器:
   
    
   
  
  
  
  
   我看过
   
    Prevent vertical UIStackView from stretching a subview?
   
   但这似乎不太适合我的情况。提前感谢您的帮助!