I want a view that is centered in the superview but that grows due the content in this case a label. But I don't want it to grow that it doesn't fit in the screen anymore so thats why I pin the left and right.
I've put on a test viewcontroller:
import UIKit
import PureLayout
final class ViewController: UIViewController {
let container: UIView = {
let container = UIView(forAutoLayout: ())
container.backgroundColor = UIColor.blackColor()
container.clipsToBounds = true
return container
}()
let label: UILabel = {
let label = UILabel(forAutoLayout: ())
label.textAlignment = NSTextAlignment.Center
label.numberOfLines = 1
label.textColor = UIColor.redColor()
label.text = "This is a very very very long message"
return label
}()
var rightView: UIView = {
let view = UIView(forAutoLayout: ())
view.backgroundColor = .redColor()
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.container.addSubview(self.label)
self.view.addSubview(self.container)
self.view.addSubview(self.rightView)
self.container.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 20)
self.container.autoAlignAxisToSuperviewAxis(.Vertical)
self.container.autoSetDimension(.Height, toSize: 36)
self.container.layer.cornerRadius = 18
self.container.autoPinEdge(.Right, toEdge: .Left, ofView: self.rightView, withOffset: -20, relation: .LessThanOrEqual)
self.container.autoPinEdgeToSuperviewEdge(.Left, withInset: 20, relation: .GreaterThanOrEqual)
self.container.setContentCompressionResistancePriority(UILayoutPriorityRequired, forAxis: .Horizontal)
self.label.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsetsMake(10, 20, 10, 20))
self.rightView.autoPinEdgeToSuperviewEdge(.Right, withInset: 5)
self.rightView.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 20)
self.rightView.autoSetDimension(.Width, toSize: 50)
self.rightView.autoSetDimension(.Height, toSize: 60)
}
}
The result of this is:
Why is the black view not growing until it can't due the left and right constraint? The number of lines is 1 and the ContentCompressionResistancePriority is on?