Last UIButton is unresponsive in UIStackView

60 Views Asked by At

I have programmatically added UIStackView to the UIViewcontroller's view and added further buttons and labels as sub arranged view to stackview, but the last added button is not responding.

override init(frame: CGRect) {
    super.init(frame: frame)
    addSubview(contentStackView)
    contentStackView.fillSuperviewHorizontally()
    contentStackView.topAnchor ~ topAnchor
    contentStackView.bottomAnchor ~ bottomAnchor | .other(.defaultLow - 1)

    contentStackView.addArrangedSubview(restorePurchaseButton)
    if !isPhone {
        contentStackView.setCustomSpacing(40, after: restorePurchaseButton)
    }
    contentStackView.addArrangedSubview(taxesLabel)
    contentStackView.addArrangedSubview(descriptionLabel)
    contentStackView.addArrangedSubview(UIStackView(axis: .vertical, arrangedSubviews: [contactUsLabel, supportButton]))
    contentStackView.addArrangedSubview(backToTopButton)
    backToTopButton.backgroundColor = .red
    contentStackView.backgroundColor = .green
}

Back to top button is unresponsive but it is visible on the device. This is how it is created:

private lazy var backToTopButton: UIButton = {
       let button = UIButton(type: .system)
       button.apply(styles: Style.subscriptionFooterButton)
       setButtonAttributedText(L10n.button.backToTop, for: button)
       button.addTarget(self, action: #selector(backToTopDidTap(_:)), for: .primaryActionTriggered)
       return button
 }()

lazy var contentStackView: UIStackView = {
       let stackView = UIStackView(frame: .zero)
       stackView.axis = .vertical
       stackView.spacing = 24
       stackView.alignment = .center
       return stackView
}() 

if I change the position of buttons then it would work, i.e if I keep back to top button above contactus , backToTop starts working and contact us doesn't respond.

0

There are 0 best solutions below