[UIKit学习]08.关于自定义控件

自定义控件

选用xib用自定义view代码与xib相关联

示例代码

+ (instancetype)shopView

{

return [self shopViewWithShop:nil];

}

+ (instancetype)shopViewWithShop:(XMGShop *)shop

{

//*注:自定义控件时,尽量把所有关于控件本身逻辑在控件本身处理

XMGShopView *shopView = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];

shopView.shop = shop;

return shopView;

}

- (void)setShop:(XMGShop *)shop

{

_shop = shop;

// 设置子控件的数据

//    UIImageView *iconView = [self viewWithTag:10];

//    UIImageView *iconView = [self.subviews firstObject];

self.iconView.image = [UIImage imageNamed:shop.icon];

//    UILabel *nameLabel = [self viewWithTag:20];

//    UILabel *nameLabel = [self.subviews lastObject];

self.nameLabel.text = shop.name;

}

上一篇:Vue.js 2.x笔记:状态管理Vuex(7)


下一篇:如何让自己定义的memory使用fpga自带的memory资源