IView - 流式布局的 UIView

IView 是 UIView 的继承, 实现了控件的流式布局, 同时, 你仍然可以使用 UIView 的所有功能和属性.

IView 除了实现流式布局, 还提供了最常见最有用的展现样式, 而这些样式如果用原生的 UIView 是无法实现的, 或者不容易实现. 例如, 边框, 分隔线, 虚线, 背景, 等等.

XML

<div style="background: #f33;">
</div>

API

typedef enum{
	IEventHighlight    = 1<<0,
	IEventUnhighlight  = 1<<1,
	IEventClick        = 1<<2,
	IEventTap          = IEventClick,
	IEventChange       = 1<<3,
	IEventReturn       = 1<<4,
}IEventType;

typedef enum{
	IRefreshNone,
	IRefreshMaybe,
	IRefreshBegin,
}IRefreshState;


@interface IView : UIView

@property (nonatomic, readonly) IStyle *style;

+ (IView *)viewWithUIView:(UIView *)view;
+ (IView *)viewWithUIView:(UIView *)view style:(NSString *)css;

+ (IView *)namedView:(NSString *)name;
+ (IView *)viewFromXml:(NSString *)xml;
+ (void)loadUrl:(NSString *)url callback:(void (^)(IView *view))callback;

- (id)data;
/**
 * override this method when IView is used as ITable row(MUST call [super setData])
 */
- (void)setData:(id)data;

// only available when init with xml or file
- (IView *)getViewById:(NSString *)vid;

/**
 * Add a view(instance of UIView or IView subclass) into subviews list,
 * apply style on the added view.
 */
- (void)addSubview:(UIView *)view style:(NSString *)css;
/**
 * This method will traverse up the view hierarchy to find and return
 * the first UIViewController, if not any found, it will return nil.
 */
- (UIViewController *)viewController;


- (void)show;
- (void)hide;
- (void)toggle;

- (void)bindEvent:(IEventType)event handler:(void (^)(IEventType event, IView *view))handler;
/**
 * event can be combined by | operator.
 */
- (void)addEvent:(IEventType)event handler:(void (^)(IEventType event, IView *view))handler;
/**
 * event can not be combined.
 */
- (BOOL)fireEvent:(IEventType)event;

@end

Demo

IView *view = [[IView alloc] init];
[view.style set:@"height: 100; background: #ff3;"];
IView *sub = [[IView alloc] init];
[sub.style set:@"width: 100; height: 50; background: #ccf;"];
[view addSubview:sub];