RubyMotion DSL for UIKit.
Version 0.6.x
Breaking changes:
Block scoping is removed, i.e. no need to pass in locals.
Previous
classViewControllerdefviewDidLoadsetupview,controller: selfdotable_viewdelegate: controller,dataSource: controllerendendendNow
classViewControllerdefviewDidLoadsetupviewdotable_viewdelegate: self,dataSource: selfendendendadd is renamed to add_view for clarity.
Add the gem to your Gemfile
gem 'simple-view'
Then bundle install
Require SimpleView in Rakefile
$:.unshift("/Library/RubyMotion/lib")require'motion/project'require'simple-view'Motion::Project::App.setupdo |app|
...
endclassYourViewController < UIViewControllerincludeSimpleView::LayoutdefviewDidLoadsetupcontent_viewdolabeltop:0,left: 0,width: 200,height: 20,text: "Choose your lucky word",text_color: "#eee"image_viewtop: 50,left: 50,right: 50,image: "sample.jpg"toolbarleft: 0,right: 0,bottom: 0endendendUse block for more control over the view instance
defviewDidLoadsetupviewdobuttontint_color: '#f00'do |button|
button.setTitle"Submit"forState: UIControlStateNormalendendendSimpleView provides shorthand methods for most UIKit classes
defviewDidLoadsetupviewdolabeltext: 'Hi there!'# shorthandadd_viewUILabel,text: 'Hi there!'# same as aboveendend- UIActionSheet via
action_sheet - 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 can work with any custom views and controls
setupviewdoadd_viewCustomViewClass,name: "custom_view"...
endDefine default style and apply to UI classes automatically
classAppDelegatedefapplication(application,didFinishLaunchingWithOptions:launchOptions)SimpleView::Styles.defineUILabel,font: "italic 13",text_color: "#999"endendclassViewControllerincludeSimpleView::LayoutdefviewDidLoadsetupviewdolabeltext: "Label with default style!"endendendDefine custom styles and mix with default style
classAppDelegatedefapplication(application,didFinishLaunchingWithOptions:launchOptions)SimpleView::Styles.defineUILabel,font: "13"SimpleView::Styles.define:darkcolor,text_color: "#999"SimpleView::Styles.define:title,font: "bold 15"endendclassViewControllerincludeSimpleView::LayoutdefviewDidLoadsetupviewdolabelstyles: :darkcolor,text: "13 font with dark color"labelstyles: [:darkcolor,:title],text: "bold 15 font with dark color"endendendPosition the view without doing a lot of calculation
setupviewdotoolbarbottom: 10,left: 10,right: 10endsetupviewdotable_viewwidth: 100.percent,height: 100.percentendTag view with name string and find them with ease
defviewDidLoadsetupviewdolabelname: 'desc'labelname: 'price'endenddefsomeOtherMethodprice_label=view.find('price')desc_label=price_label.sibling('desc')end