Skip to content

Repository files navigation

SimpleView

RubyMotion DSL for UIKit.

Change log

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: controllerendendend

Now

classViewControllerdefviewDidLoadsetupviewdotable_viewdelegate: self,dataSource: selfendendend

add is renamed to add_view for clarity.

Installation

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|
...
end

Usage

classYourViewController < 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: 0endendend

Use block for more control over the view instance

defviewDidLoadsetupviewdobuttontint_color: '#f00'do |button|
button.setTitle"Submit"forState: UIControlStateNormalendendend

UIKit support

SimpleView 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

Custom view support

SimpleView can work with any custom views and controls

setupviewdoadd_viewCustomViewClass,name: "custom_view"...
end

Style Template

Define 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!"endendend

Define 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"endendend

View positioning and sizing

Position the view without doing a lot of calculation

setupviewdotoolbarbottom: 10,left: 10,right: 10end
setupviewdotable_viewwidth: 100.percent,height: 100.percentend

View tagging with string

Tag 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

About

RubyMotion DSL for UIKit

Resources

Stars

102 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages