Permalink
Browse files

Merge pull request #11 from clayallsopp/master

Added helper for UIButton
  • Loading branch information...
2 parents 08d6b85 + be2fa6c commit ef429db21e5b90e8fedef75e3453717ef254d402 @mattetti mattetti committed May 9, 2012
Showing with 17 additions and 0 deletions.
  1. +10 −0 README.md
  2. +7 −0 lib/ui_button.rb
View
@@ -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
@@ -0,0 +1,7 @@
+class UIButton
+ def when(events, &block)
+ @callback ||= {}
+ @callback[events] = block
+ addTarget(@callback[events], action:'call', forControlEvents: events)
+ end
+end

0 comments on commit ef429db

Please sign in to comment.