2

superView我想在其右下角布置一个标签,8pt10pt从底部开始

这是我的代码:

  let label = UILabel(frame: CGRectZero)
  label.text = "text goes here"
  label.textColor = UIColor.whiteColor()
  label.translatesAutoresizingMaskIntoConstraints = false
  label.numberOfLines = 0
  label.textAlignment = .Right
  label.backgroundColor = UIColor.blackColor()
  label.font = UIFont(name: "TheSans-Plain", size: 17)
  imageTitleContainer.addSubview(label)


    let label_constraint_H:Array = NSLayoutConstraint.constraintsWithVisualFormat("H:|-(>=8)-[label]-(8)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["label":label])

    let label_constraint_V:Array = NSLayoutConstraint.constraintsWithVisualFormat("V:[label]-(10)-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["label":label])

    imageTitleContainer.addConstraints(label_constraint_H)
    imageTitleContainer.addConstraints(label_constraint_V)`

但我要Unable to simultaneously satisfy constraints进去了console

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7ff55acf24c0 H:[UILabel:0x7ff55acf1af0'text goes here']-(8)-| (Names: '|':UIView:0x7ff55acbf430 )>

注意:0x7ff55acbf430是我imageTitleContainer的代码

更新:其他约束: "<NSLayoutConstraint:0x7ff55accdc80 H:|-(0)-[UIView:0x7ff55acbf430] (Names: '|':UIView:0x7ff55acca080 )>", "<NSLayoutConstraint:0x7ff55accdcd0 H:[UIView:0x7ff55acbf430]-(0)-| (Names: '|':UIView:0x7ff55acca080 )>", "<NSLayoutConstraint:0x7ff55acf2450 H:|-(>=8)-[UILabel:0x7ff55acf1af0'text goes here'] (Names: '|':UIView:0x7ff55acbf430 )>", "<NSLayoutConstraint:0x7ff55acf24c0 H:[UILabel:0x7ff55acf1af0'text goes here']-(8)-| (Names: '|':UIView:0x7ff55acbf430 )>", "<NSLayoutConstraint:0x7ff55adb3830 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7ff55acca080(0)]>" )

4

1 回答 1

0

尝试降低您的限制之一的优先级,例如

H:|-(>=8@999)-[label]-(8)-|

必须这样做以允许 UICollectionView 完成其布局工作。注意命名的零宽度约束UIView-Encapsulated-Layout-Width会破坏您的布局。

于 2015-12-25T23:40:05.307 回答