SwiftyWalkthrough icon indicating copy to clipboard operation
SwiftyWalkthrough copied to clipboard

Button in customView

Open rafaelbletro opened this issue 8 years ago • 1 comments

Hi, congratulations this is a vey good class.

I`m creating a subclass and inside has a button, i used your example of subclass to create mine subclass.

`

lazy var helpLabel: UILabel = self.makeHelpLabel()
lazy var titleLabel: UILabel = self.makeTitleLabel()
lazy var image: UIImageView = self.makeImage()
lazy var entendiBtn: UIButton = self.makeButton()

init() {
    super.init(frame: CGRectZero)
    self.userInteractionEnabled = true;

    addSubview(titleLabel)
    addSubview(helpLabel)
    addSubview(entendiBtn)

}

`

You know how i get touchevent on button? I test override the method hittest, but called two times the delegate.

   override internal func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {

        let currentView = self.entendiBtn
        let convertedPoint = currentView.convertPoint(point, fromView: self)

        if currentView.pointInside(convertedPoint, withEvent: event) {
            delegate?.willInteractWithView?(currentView)
            return currentView.hitTest(convertedPoint, withEvent: event)
        }

        return super.hitTest(point, withEvent: event)
    }

rafaelbletro avatar Aug 16 '16 12:08 rafaelbletro

Hi @rafaelbletro, have a look at this section on the documentation. However, you can handle interactions with UIButton as usual (i.e. touchUpInside) if that's what you're trying to do.

ruipfcosta avatar Oct 14 '16 23:10 ruipfcosta