-
Notifications
You must be signed in to change notification settings - Fork 257
Getting Started
FlexLib is a framework for creating native iOS applications using a human-readable markup language, similar to Android and .NET development way.
FlexLib is developed as freely open-source project on Github. You can get it through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'FlexLib'
Then import FlexLib.h in your project.pch:
#import <FlexLib/FlexLib.h>
Maybe you will get error when pod install. If so you will need to update your local pod repository. See more here
<?xml version="1.0" encoding="utf-8"?>
<UIView layout="flex:1,justifyContent:center,alignItems:center" attr="bgColor:white">
<UIView name="_test" onPress="onPressTest" layout="width:40,height:40" attr="bgColor:lightGray"/>
</UIView>
This demo is small but there are some knowledge you should know.
- Any UIView descendant in app will be available in xml layout.
- Every element support four xml attribute: name, onPress, layout, attr.
- The element with 'name' will be binded to the variable in owner. Warning: It may cause memory leak if the name not exist in owner but declared for the element.
- 'onPress' will be binded to the method in owner.
- 'layout' support all the yoga-flexbox attributes like width, margin, padding, flexDirection, ...
- 'attr' support the view attribute like bgColor, fontSize, color, ...
- Normally the top view in xml layout should have layout attribute with 'flex:1', so it will fill the whole area.
- For view controller, the background color of the top view in xml layout will be synchronized to the view of the view controller.
Flexbox Introduction & performance (in Chinese)
Tutorial 1: Create View Controller with xml layout
Tutorial 2: Create Table Cell with xml layout
Tutorial 3: Embed xml layout into traditional view hierarchy
Tutorial 4: Use custom view in xml layout
Tutorial 5: Create reusable view using xml layout file