【问题标题】:Adding height constraint to UILabel issue向 UILabel 问题添加高度约束
【发布时间】:2017-11-24 19:28:21
【问题描述】:

在 Swift3 中想向 UILabel 添加高度约束 20px 但没有运气,我错过了什么?

addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 1, constant: 20))

此代码适用于 Swift2。

谢谢。

【问题讨论】:

    标签: ios xcode swift3 swift2


    【解决方案1】:

    一种直接的方式:

    // assuming your UILabel is myLabel
    myLabel.heightAnchor.constraint(equalToConstant: 20.0).isActive = true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多