Using NUI with RubyMotion

NUI is an open-source library that allows you to style your iOS applications using CSS-like files and syntax. In my opinion, NUI carries few benefits over its commercial, KickStart backed, competitor Pixate. First; NUI allows you to style your application on the fly while it’s running in the simulator. And Second; NUI styled-elements are not masked/wrapped in their special classes (like those PX* classes with pixate), rather, they remain as their original iOS declarations. The second point makes debugging the simulated application and tracking ons-creen objects (using cmd-hover) much easier.

In your RubyMotion application’s Rakefile: {% highlight ruby %} Motion::Project::App.setup do |app| #… app.pods do # … pod ‘NUI’ end end {% endhighlight %} Then run `

“ `

Create a theme.nss file (which will include your application’s stylesheet). Then in your “{% highlight ruby %} class AppDelegate

@@nui_settings = NUISettings.init @@nui_settings.setAutoUpdatePath(“/absolute/path/to/project/and/theme.nss”)

def application(application, didFinishLaunchingWithOptions:launchOptions)

12@nui = NUIAppearance.init# ...   end

end {% endhighlight %}

Run `

` and check your application in the simulator. Now, any changes to the <ts_code></ts_code> file will be reflected right away to the running application in the simulator. Happy styling