Skip to content

XCEssentials/ViewEvents

Repository files navigation

GitHub tag CocoaPods CocoaPods license

Introduction

Helpers for managing handlers of UIControl-based events and gesture recognizers.

How to install

The recommended way is to install using CocoaPods:

pod 'XCEViewEvents', '~> 1.1'

How it works

This library provides set of helper functions via extensions for UIControl and UIView classes. These functions are just syntax sugar on top of standard UIKit API.

How to use

For example, here is how to add handler to UIButton instance button for onTouchUpInside ("tap") event (assume we have an appropriate function called buttonTapHandler on self):

button.onTouchUpInside.add(
  #selector(buttonTapHandler),
  of: self
)

Alternatively, if self conforms to HandlersOwner protocol, the aboe example can be written like this:

self.bind(
  #selector(buttonTapHandler),
  with: button.onTouchUpInside
)

Gesture recognizers

Same approach is used to bind handlers with gesture recognizers.

For example, here is how to add handler to UIImageView instance image for "tap" gesture (assume we have an appropriate function called tapGestureHandler on self):

image.onTapGesture.addRecognizer(#selector(tapGestureHandler), of: self){ gesture in
  // configure gesture here
}

Alternatively, if self conforms to HandlersOwner protocol, the aboe example can be written like this:

self.bind(#selector(tapGestureHandler), with: image.onTapGesture){ gesture in
  // configure gesture here
}

About

[DEPRECATED - use 'SwiftUI' instead] Helpers for managing handlers of UIControl-based events and gesture recognizers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published