Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from clayallsopp/master

Added helper for UIButton
  • Loading branch information...
commit ef429db21e5b90e8fedef75e3453717ef254d402 2 parents 08d6b85 + be2fa6c
@mattetti mattetti authored
Showing with 17 additions and 0 deletions.
  1. +10 −0 README.md
  2. +7 −0 lib/ui_button.rb
View
10 README.md
@@ -113,3 +113,13 @@ Extra methods on `UIView` for working with gesture recognizers. A gesture recogn
```
There are similar methods for pinched, rotated, swiped, panned, and pressed (for long presses). All of the methods return the actual recognizer object, so it is possible to set the delegate if more fine-grained control is needed.
+
+## UIButton
+
+Helper methods to give `UIButton` a Ruby-like interface. Ex:
+
+```ruby
+button.when(UIControlEventTouchUpInside) do
+ self.view.backgroundColor = UIColor.redColor
+end
+```
View
7 lib/ui_button.rb
@@ -0,0 +1,7 @@
+class UIButton
+ def when(events, &block)
+ @callback ||= {}
+ @callback[events] = block
+ addTarget(@callback[events], action:'call', forControlEvents: events)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.