-
Notifications
You must be signed in to change notification settings - Fork 257
Tutorial 4: Use custom view in xml layout
zhenglibao edited this page Jan 13, 2018
·
1 revision
The custom view has two requirements:
- All the initiation must be done in init method. All other initWith... method will not be called.
- Use FLEXSET macro to extend the view attribute. All the extended attribute will be available in xml layout Then you can use it in xml layout like any system controls.
If the initiation can't be done in init method, you can override createView:Name: method to make custom initiation.
-(UIView*)createView:(Class)cls
Name:(NSString*)name
{
if([@"_segment" compare:name]==0){ // custom initiation
NSArray* items=@[@"item1",@"item2",@"item3"];
return [[UISegmentedControl alloc]initWithItems:items];
}
return nil;
}
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