CustomUIView通过xib实现一个简单地自定义视图

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

1/**2* 使用Custom UIView的这条路,我走的很不顺利,前期犯2,中期有事,浪费了很多时间!3* 现在空闲的时间不多了,只能抓紧时间写两个小demo,一来做练习,二来整理下也许能给要学习的人一些帮助!4*/

1/**2* Custom UIView常用的三种实现方法:3* Method_1:通过初始化的方式(eg:UITableViewCell的重写)4Method_2:通过drawRect的方法,使用代码自己画出想要的视图5Method_3:通过xib6*/

/**

* 初始化代码:

*

* @return [nibView objectAtIndex:0]*/+ (ZYCustomView *)initCustomView

{

NSArray* nibView = [[NSBundle mainBundle] loadNibNamed:@"ZYCustomView"owner:nil options:nil];return[nibView objectAtIndex:0];

}

/**

* 在ViewController里引用*/- (void)viewDidLoad

{

[super viewDidLoad];//Do any additional setup after loading the view, typically from a nib.ZYCustomView*test =[ZYCustomView initCustomView];

test.backgroundColor=[UIColor yellowColor];

test.clipsToBounds=YES;

test.frame= CGRectMake(0,20,320,200);

test.lb1.text=@"我是第一行";

[self.view addSubview:test];

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航