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

1 /**
2  *  使用Custom UIView的这条路,我走的很不顺利,前期犯2,中期有事,浪费了很多时间!
3  *  现在空闲的时间不多了,只能抓紧时间写两个小demo,一来做练习,二来整理下也许能给要学习的人一些帮助!
4  */
1 /**
2  *  Custom UIView常用的三种实现方法:
3  *  Method_1:通过初始化的方式(eg:UITableViewCell的重写)
4     Method_2:通过drawRect的方法,使用代码自己画出想要的视图
5     Method_3:通过xib
6  */

 

 

 

 

 

/**
 *  初始化代码:
 *
 *  @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];
}

转载于:https://www.cnblogs.com/zylike/p/3753337.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值