今天项目中需要自定义的table区头和区脚,而又无法直接在IB中实现自定义的样式,所以创建了一个xib自定义的view 去实现,具体步骤为:
首先创建view 类,无法携带xib模板
然后单独创建一个view 的IB模板
把calss 关联起来
修改属性控制器size类型为freeform,(为了自定义frame)
给自定义的view添加类方法,
#import "CustomView.h"
@implementation CustomView
+(CustomView *)instanceView
{
NSArray* nibView = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil];
return [nibView objectAtIndex:0];
}
@end
这就创建了一个可视化操作的自定义大小的View,在需要用的地方可随时调用,例如:
_table.tableFooterView = [CustomView instanceView];
最后,如果需要在代码中修改视图内容,可在下面初始化方法中实现
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if(self)
{
}
return self;
}