Module: SimpleView::Layout
- Extended by:
- Layout
- Included in:
- Layout, 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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/simple_view/layout.rb', line 34 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, ::, ::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
11 12 13 14 15 16 17 |
# File 'lib/simple_view/layout.rb', line 11 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
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/simple_view/layout.rb', line 19 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
5 6 7 8 9 |
# File 'lib/simple_view/layout.rb', line 5 def setup view, &block view_stack.push view block.call if block_given? view_stack.pop end |
#view_stack ⇒ Object
30 31 32 |
# File 'lib/simple_view/layout.rb', line 30 def view_stack @view_stack ||= [] end |