I have a simple custom UIView (The view with white background on the screenshot) using xib and custom class derived from UIView.
Inside I have a UILabel and a button on the same line ant that's all.
The size of the button is fixed. The width of the label must be adjusted on its content.
What I would like is : - fit the size of the label to its content - set the position of the button always just after the label - fit the custom to its content
Like this :
How can I proceed to do this ?
Add content :
class Keyword: UIView {
@IBOutlet weak var label: UILabel!
@IBOutlet var contentView: UIView!
override init(frame: CGRect) {
super .init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super .init(coder: aDecoder)
commonInit()
}
fileprivate func commonInit() {
Bundle.main.loadNibNamed("Keyword", owner: self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
}
override var intrinsicContentSize: CGSize {
let height = CGFloat(21)
return CGSize(width: UIViewNoIntrinsicMetric, height: height)
}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}
UILabel contraints :
Tick UIButton constraints :