您的位置:首页 > 产品设计 > UI/UE

用xib自定义UIView并在代码中使用--iOS

2016-08-13 12:01 423 查看
首先新建一个空的xib文件:



将size改为freedom:



然后在xib中自定义视图(添加自己想要的其它视图):



要写好约束, 创建一个继承uiview的类和他关联,然后就可以调用了.

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//获得nib视图数组

NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"HeadView" owner:nil options:nil];
// Find the view among nib contents (not too hard assuming there is only one view in it).
// 得到最后一个view

HeadView *headView = [nibContents lastObject];
headView.frame = CGRectMake(0, 0, 300, 200);
//headView.backgroundColor = [UIColor blueColor];
_tableView.tableHeaderView = headView;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: