From cab044b35fb4f38a35544ab7cf83124149e2af3f Mon Sep 17 00:00:00 2001 From: Abel Sanchez Date: Tue, 15 Aug 2017 19:32:51 -0700 Subject: [PATCH] Updating README --- README.md | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dbdb0e0..47a1eb7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ViewBuilder -View Builder Project is a XML document base declarative way for building any user interface in iOS. With is own built-in layout engine. +View Builder Project is a XML document based declarative way for building an user interface in iOS. With is own built-in layout engine. # Features @@ -10,12 +10,13 @@ View Builder Project is a XML document base declarative way for building any use - Gradients and SVG Vector Graphics support. You can easily: - - Have all your resources and reuse them andanywhere. + - Have all your resources and reuse them anywhere. - Define object styles that you can freely apply. - - Have view templates will help you to be more productive. + - Having view templates will help you to be more productive. - Use any custom object in your documents and extend document language. -Documents are handled with performance in mind. They are cached and automatically evicted by default. Having concepts like mutability that help to optimize string parsing. +Documents are handled with performance in mind. They are cached and automatically evicted by default. Having concepts like mutability help to optimize string parsing. + ## Examples @@ -34,6 +35,7 @@ To start will be cool to watch this [video][demovideo]. ``` **Some sample view** + *Defining a scrollable section that will contain a label* ```xml @@ -45,6 +47,7 @@ To start will be cool to watch this [video][demovideo]. ``` **Using some of those resources is very easy** + ```xml @@ -60,11 +63,78 @@ let view = DocumentBuilder.shared.load(path) ``` **Having references to any object in document will be like** + All named nodes could be accessed using `documentReferences` attached property. ```swift - let label = container.documentReferences!["contentLabel"] as! UILabel +let label = container.documentReferences!["contentLabel"] as! UILabel +``` + +**How to create a UIViewController binded to a document** + +Since `UIViewController.loadView()` function handle custom view creations. We only need to override this function, but remember never calling it's super implementation. +```swift +override func loadView() { + view = DocumentBuilder.shared.load(Bundle.main.path(forResource: "View", ofType: "xml")!) +} +``` +in Objective-C: +```m +- (void) loadView { + self.view = [[DocumentBuilder shared] loadView:[[NSBundle mainBundle] pathForResource: @"View" ofType: @"xml"] options: nil]; +} +``` + +***How to create a custom view from a document*** + +Could be done in several ways. One is as we show before to load a view from a document insert this as a child view and access it's named element from `documentReferences` property. + +Another approach is to create a subview class and load it using `UIView.loadFromDocument` extension. + +```swift +public class CustomView: StackPanel { + init() { + super.init(frame: CGRect.zero) + initialize() + } + + required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + initialize() + } + + private func initialize() { + loadFromDocument(Bundle.main.path(forResource: "CustomView", ofType: "xml")!) + } +} ``` +and define it's content in a document: + +```xml + + + + + + + +``` + +It's important to mention that content node should be same type as `CustomView` parent class `StackPanel`. + + ## Layout Engine ViewBuilder is provided with a built-in layout engine. Comparing layouts could be very hard but having some metrics will be helpful to understand what work better to you. @@ -72,7 +142,7 @@ ViewBuilder is provided with a built-in layout engine. Comparing layouts could b * **Productivity** - How much effort is needed to build and define UI elements. * **Performance** - How faster is done the measurement/layout/rendering process. * **Learning Curve** - How easy to learn and to use is that technology. -* **Readability** - How easy is to review, its diff compatible, etc. +* **Readability** - How easy is to review, it's diff compatible, etc. * **Flexibility** - How easy is to modify, customize and extend. Here some existing layout engines compared together with our PanelLayout: @@ -87,6 +157,20 @@ Here some existing layout engines compared together with our PanelLayout: *Is important to hightlight that those numbers are not proportional to results* +## Document + +## Extension + +## Cocoapods + +Adding dependency will be just including `ViewBuilder` pod. Remember to add `use_frameworks` to podfile since ViewBuilder is implemented as a framework in swift. + +```podfile +use_frameworks! + + pod 'ViewBuilder', '~> 0.0.1' +``` + ## Todos - Write MORE Tests