rubymotion interface builder support (yes, with outlets)
Add this line to your application's Gemfile:
gem 'ib'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ib
In your Rake file:
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
# if you use bundler
require 'bundler'
Bundler.require
# if you are not using bundler
require 'rubygems'
require 'ib'
Motion::Project::App.setup do |app|
# ...
end
extend your class with IB module
class HelloController < UIViewController
extend IB
# define ib outlet
outlet :title, UILabel # @property IBOutlet UILabel * title;
outlet :untyped_label # @property IBOutlet id untyped_label;
# define ib outlet collection
outlet_collection :labels, UILabel # @property IBOutletCollection(UILabel) NSArray * labels;
# define ib action
def someAction sender
end
end
NOTE: If you include methods and attributes from module, you can use ib_outlet
and ib_action
to make them visible in designer
module TouchLogger
def controlTouched sender
puts "touched"
end
end
class LogController < UIViewController
extend IB
include TouchLogger
ib_action :controlTouched
end
Generate controller with folllowing command:
ib c Hello UIViewController \
--outlets scroller:UIScrollView btn_hello: \
--actions say_hello \
--accessors data_source
The generated file:
class HelloController < UIViewController
extend IB
attr_accessor :data_source
## ib outlets
outlet :scroller, UIScrollView
outlet :btn_hello
def say_hello(sender)
# TODO Implement action here
end
end
Run rake ib:open
create Storyboard or nibs (put them in resources folder) and you will be able to bind outlets and actions to your ruby code.
Note : add ib.xcodeproj to your .gitignore
Here is sample app
- clone it
- run
bundle
- run
rake ib:open
to change story board - run
rake
to run app in simulator
Note : this app is build for iOS 6.0
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request