A DSL for UIKit for RubyMotion.
Demo app: Currency
Add the gem to your Gemfile
gem 'simple-view', :git => 'https://github.com/seanho/SimpleView.git'
Then bundle install
Require SimpleView in Rakefile
$:.unshift("/Library/RubyMotion/lib")require'motion/project'require'simple-view'Motion::Project::App.setupdo |app|
...
enddefviewDidLoadUI::Layouts.setup(view)dolabelwidth: 200,height: 20,text: "Choose your lucky word",color: "#eee"image_viewtop: 50,left: 50,right: 50,image: "sample.jpg"toolbaranchors: [:bottom]endendEverything inside setup block will be added to the view automatically.
Hash parameters works only on KVC-compliant properties. To configure view object in more detail, use a block
defviewDidLoadUI::Layouts.setup(view)dobuttondo@view.setTitle("Submit"forState: UIControlStateNormal)endendend- UIActivityIndicatorView via
activity_indicator - UIButton via
button - UIDatePicker via
date_picker - UIImageView via
image_view - UILabel via
label - UIPageControl via
page_control - UIPickerView via
picker_view - UIProgressView via
progress_view - UIScrollView via
scroll_view - UISearchBar via
search_bar - UISegmentedControl via
segmented_control - UISlider via
slider - UIStepper via
stepper - UISwitch via
switch - UITabBar via
tab_bar - UITableView via
table_view - UITableViewCell via
table_view_cell - UITextField via
text_field - UITextView via
text_view - UIToolbar via
toolbar - UIView via
rect - UIWebView via
web_view
SimpleView works not only with UIKit, custom or 3rd party created views and controls can also be used
UI::Layouts.setup(view)doaddCustomViewClass,name: "custom_view"...
endExperimental. Might change in future.
Define a style and apply to multiple views with ease.
classAppDelegatedefapplication(application,didFinishLaunchingWithOptions:launchOptions)UI::Styles.define:tag_label,font: "italic 13",text_color: "#999"endendclassViewControllerdefviewDidLoadUI::Layouts.setup(view,controller: self)dolabelstyles: :tag_label,text: "Left",anchors: [:left]labelstyles: :tag_label,text: "Right",anchors: [:right]endendendUI::Layouts.setup(view)dotoolbarbottom: 10,left: 10,right: 10,anchors: [:bottom]endHash parameters will automatically turns into instance variable within the block
defviewDidLoadUI::Layouts.setup(view,controller: self)dotable_viewdelegate: @controller,dataSource: @controllerendendNo need to declare ivar, no need to use integer tag, just name your view and access it by the name.
defviewDidLoadUI::Layouts.setup(view)dolabelname: "price_label"# give a name to the labelendenddefsomeOtherMethodview.subview("price_label")# get the labelend