README.md in motion-kit-0.10.0 vs README.md in motion-kit-0.10.1

- old
+ new

@@ -268,10 +268,50 @@ end ``` +### Setting a custom root view + +If you need to use a custom root view, you can use the `root` method from within +the `layout` method. When you create or assign the root view this way, you must +assign subviews and styles *inside* a block that you pass to `root`. + +```ruby +def layout + root(SomeOtherViewclass) do + add UILabel + end +end +``` + +You can also pass in a root view to your layout, like this: + +```ruby +def loadView + @layout = MyLayout.new(root: self.view).build +end +``` + +Make sure to call `.build`; otherwise, the layout will be returned but the view not built. + +In this case, if you want to style the root view, just refer to it in your layout: + +```ruby +def layout + root :my_root_view do + # ... + end +end + +def my_root_view_style + background_color UIColor.grayColor +end +``` + +This is especially useful with collection views, table views, and table cells. + ### How do styles get applied? If you've used RMQ's Stylers, you'll recognize a very similar pattern here. In RMQ the 'style' methods are handed a 'Styler' instance, which wraps access to the view. In MotionKit we make use of `method_missing` to call these methods @@ -636,11 +676,11 @@ class MainController < UIViewController def loadView @layout = MainLayout.new - self.view = @layout + self.view = @layout.view end # for the constraints to work reliably they should be added in this method: def updateViewConstraints @layout.add_constraints(self) @@ -762,47 +802,9 @@ The OS X helpers are really nice, because it tries to hide most of the annoying subtletees of the NSCell/NSControl dichotomy. gem install sweet-kit - -### Setting a custom root view - -If you need to use a custom root view, you can use the `root` method from within -the `layout` method. When you create or assign the root view this way, you must -assign subviews and styles *inside* a block that you pass to `root`. - -```ruby -def layout - root(SomeOtherViewclass) do - add UILabel - end -end -``` - -You can also pass in a root view to your layout, like this: - -```ruby -def loadView - @layout = MyLayout.new(root: self.view) -end -``` - -In this case, if you want to style the root view, just refer to it in your layout: - -```ruby -def layout - root :my_root_view do - # ... - end -end - -def my_root_view_style - background_color UIColor.grayColor -end -``` - -This is especially useful with collection views, table views, and table cells. # Contributing We welcome your contributions! Please be sure to run the specs before you do, and consider adding support for both iOS and OS X.