Module: SimpleView::Layout
- Included in:
- SimpleViewController, UserInfoController, UserInfoHeader, ViewAnchoringController
- Defined in:
- lib/simple_view/layout.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_view(klass, options = {}, &block) ⇒ Object
- #create_view(klass, options = {}, &block) ⇒ Object
- #setup(view, &block) ⇒ Object
- #view_stack ⇒ Object
Class Method Details
.included(base) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/simple_view/layout.rb', line 32 def self.included base base.class_eval do [::UIActionSheet, ::UIActivityIndicatorView, ::UIButton, ::UIDatePicker, ::UIImageView, ::UILabel, ::UIPageControl, ::UIPickerView, ::UIProgressView, ::UIScrollView, ::UISearchBar, ::UISegmentedControl, ::UISlider, ::UIStepper, ::UISwitch, ::UITabBar, ::UITableView, ::UITableViewCell, ::UITextField, ::UITextView, ::UIToolbar, ::UIWebView].each do |klass| shorthand = "#{klass}"[2..-1].underscore.to_sym define_method(shorthand) do |*args, &block| = args[0] || {} add_view klass, , &block end end def rect( = {}, &block) add_view(::UIView, , &block); end end end |
Instance Method Details
#add_view(klass, options = {}, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/simple_view/layout.rb', line 9 def add_view klass, = {}, &block subview = create_view klass, , &block view_stack.last.addSubview(subview) unless view_stack.empty? subview end |
#create_view(klass, options = {}, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_view/layout.rb', line 17 def create_view klass, = {}, &block bounds = view_stack.empty? ? CGRectZero : view_stack.last.bounds subview = ViewBuilder.view_for klass, bounds, view_stack.push subview block.call(subview) if block_given? view_stack.pop subview end |
#setup(view, &block) ⇒ Object
3 4 5 6 7 |
# File 'lib/simple_view/layout.rb', line 3 def setup view, &block view_stack.push view block.call if block_given? view_stack.pop end |
#view_stack ⇒ Object
28 29 30 |
# File 'lib/simple_view/layout.rb', line 28 def view_stack @view_stack ||= [] end |