iOS开发好文程序员iOS进阶指南

View自定义控件的封装

2016-03-15  本文已影响256人  飞翔的道长

/**


- #####在layoutSubviews方法中设置子控件的frame(一定要调用super的layoutSubviews)

```objc
/**
*  控件大小改变事件
*/
-(void)layoutSubviews
{
    [super layoutSubviews];

    float shopW = self.frame.size.width;
    float shopH = self.frame.size.height;

    self.iconView.frame = CGRectMake(0, 0, shopW, shopW);
    self.nameLabel.frame = CGRectMake(0, shopW, shopW, shopH - shopW);
}
/**
*  Shop的set方法
*
*  @param shop
*/
-(void)setShop:(Shop *)shop
{
  _shop = shop;

  self.iconView.image = [UIImage imageNamed:shop.icon];
  self.nameLabel.text = shop.name;
}
上一篇 下一篇

猜你喜欢

热点阅读