码迷,mamicode.com
首页 > 其他好文 > 详细

view的封装,xib和stroryBoard加载及使用

时间:2016-01-03 18:24:30      阅读:547      评论:0      收藏:0      [点我收藏+]

标签:

一.view的封装:

技术分享

代码实现:

- (instancetype)init

{

    if (self = [super init]) {

        // 1.添加UIImageView对象用于显示商品的图片

        UIImageView *iconView = [[UIImageView alloc] init];

        [self addSubview:iconView];

        self.iconView = iconView;

        

        // 2.添加UILabel对象用于显示商品的名字

        UILabel *titleLabel = [[UILabel alloc] init];

        titleLabel.textAlignment = NSTextAlignmentCenter;

        [self addSubview:titleLabel];

        self.titleLabel = titleLabel;

    }

    return self;

}

 

- (void)layoutSubviews

{

    [super layoutSubviews];

    

    // 1.取出当前控件的宽度和高度

    CGFloat width = self.frame.size.width;

    CGFloat height = self.frame.size.height;

    

    // 2.调整子控件的frame

    self.iconView.frame = CGRectMake(0, 0, width, width);

    self.titleLabel.frame = CGRectMake(0, width, width, height - width);

}

 

 

二.Xib和stroyboard对比

技术分享

加载xib

技术分享

技术分享

三.利用MVC的思想对代码分组

技术分享

 

view的封装,xib和stroryBoard加载及使用

标签:

原文地址:http://www.cnblogs.com/wxdonly/p/5096765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!