I want my stack view to have three views: red image, blue image and register view. The thing is that while the red and blue button appear just fine, the register view does not.
This is how I set up and place my stack view inside my view controller view:
func setupSocialStackView() {
let socialStackView = UIStackView(arrangedSubviews: redImage, blueImage, registerView])
socialStackView.axis = .vertical
socialStackView.distribution = .fillProportionally
view.addSubview(socialStackView)
socialStackView.spacing = 8
// NSLayoutAnchor constraints here to place stack view
// inside my view controller view
}
This is the code for my register view which doesn't show up:
lazy var registerView: UIView = {
let containerView = UIView()
// Register button
let registerButton = UIButton(type: .system)
registerButton.setTitle("Register", for: .normal)
registerButton.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: UIFontWeightLight)
registerButton.titleLabel?.textAlignment = .center
registerButton.setTitleColor(UIColor.black, for: .normal)
registerButton.titleLabel?.textColor = UIColor(r: 91, g: 90, b: 90)
registerButton.addTarget(self, action: #selector(presentRegisterController), for: .touchUpInside)
containerView.addSubview(registerButton)
return containerView
}()
The other two arrange views of the stack view are UIImageView
s.
Why are the two images there and the register view is not? Am I missing something?
You don't appear to be giving your UIButton a frame size. See what you get if you add an autoresizingMask line:
registerButton.addTarget(self, action: #selector(presentRegisterController), for: .touchUpInside)
registerButton.autoresizingMask = [.flexibleWidth, .flexibleHeight]
containerView.addSubview(registerButton)
For me, I needed to add bottom, right, and left constraints for the view inside the stack view. Then it appeared.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With