Adding Interaction with UIButton

The iOS APIs include many standard UIView subclasses. Some add intricate functionality, while others are merely ornamental. UIButton is one such view, and it does exactly what it sounds like. Let’s add it to our app and see how it works.

UIButtons are created differently than normal UIViews. Instead of using alloc.initWithFrame, UIButtons are initialized using the static method UIButton.buttonWithType:. We pass an integer option, usually UIButtonTypeSystem or UIButtonTypeCustom, and get a new button. Many iOS APIs use verbose integer constants like these because more idiomatic Ruby Symbols don’t exist in the original Objective-C. Anyhow, take a look at how we add our button in AppDelegate.

Get RubyMotion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.