首页 > 其他 > 详细

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

时间:2016-01-03 18:24:04      阅读:176      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!