I’m trying to implement custom control according to official doc
The problem is that UIButton object placed into HorizontalStackVIew fills all its space ignoring its button constraints (width=4.0 height=4.0). (I tried with VerticalStackVIew and UITextView and other but it’s the same)
class MyControl: UIStackView {
override init(frame: CGRect) {
super.init(frame: frame)
setupButtons()
}
required init(coder: NSCoder) {
super.init(coder: coder)
setupButtons()
}
private func setupButtons() {
// Create the button
let button = UIButton()
button.backgroundColor = UIColor.red
// Add constraints
button.translatesAutoresizingMaskIntoConstraints = false
button.heightAnchor.constraint(equalToConstant: 4.0).isActive = true
button.widthAnchor.constraint(equalToConstant: 4.0).isActive = true
// Add the button to the stack
addArrangedSubview(button)
}
And I've got this log but don't know what to do with it:
2017-02-10 16:59:31.900999 MyControl[1835:91456] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", "", "" )
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2017-02-10 16:59:31.950461 MyControl[1835:91456] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", "", "" )
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
Xcode 8.2.1

