bhlvoong / LBTATools

Set of tools to drastically improve development speed of UI in iOS applications
MIT License
728 stars 94 forks source link

StackView set isUserInteractionEnabled false. #21

Closed sereisoglu closed 4 years ago

sereisoglu commented 4 years ago

When the stack is used on inside a button, the button cannot be clicked.

bhlvoong commented 4 years ago

I'm not sure if this is true

sereisoglu commented 4 years ago

You can check it out.

import LBTATools

class CustomButton: UIButton {

    fileprivate let backgroundView = UIView(backgroundColor: .red)

    init() {
        super.init(frame: CGRect.zero)

        stack(self.backgroundView).withWidth(200).withHeight(50)//.isUserInteractionEnabled = false
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let button = CustomButton()

        button.addTarget(self, action: #selector(handleClick), for: .touchUpInside)

        self.view.stack(
            self.view.hstack(
                button, alignment: .center
            ), alignment: .center
        )

    }

    @objc fileprivate func handleClick() {
        print("Clicked")
    }

}