I'm new to Xcode and Swift.
I'm trying to go through the sample here: https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementingACustomControl.html#//apple_ref/doc/uid/TP40015214-CH19-SW1
I believe I have my class set up correctly:
class RatingControl: UIStackView {
override init(frame: CGRect) {
super.init(frame: frame)
setupButtons()
}
required init(coder: NSCoder) {
super.init(coder: coder)
setupButtons()
}
private func setupButtons(){
let button = UIButton()
button.backgroundColor = UIColor.red
button.translatesAutoresizingMaskIntoConstraints = false
button.heightAnchor.constraint(equalToConstant: 44.0).isActive = true
button.widthAnchor.constraint(equalToConstant: 44.0).isActive = true
addArrangedSubview(button)
}
}However, when I run the app in Simulator, the UIButton does not have a height and width of 44, but instead takes up the full area of the containing UIStackView.
I can see the confilicting constraints in the output:
"<NSLayoutConstraint:0x60800009fb80 'UIView-Encapsulated-Layout-Height' FoodTracker.RatingControl:0x7fa5d7505560.height == 110 (active)>"
"<NSLayoutConstraint:0x60800009fb30 'UIView-Encapsulated-Layout-Width' FoodTracker.RatingControl:0x7fa5d7505560.width == 200 (active)>"
What are UIView-Encapsulated-Lauout-Height and UIView-Encapsulated-Layout-Width? The guide doesn't mention them. How do I get my programmatically added button to respect the constraints I've given it, rather than these inherited constraints?