[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;
}
?
轉載于:https://www.cnblogs.com/zhangjingyangjinjin/p/5226650.html
總結
以上是生活随笔為你收集整理的[UIKit学习]08.关于自定义控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring AOP 之五:Spring
- 下一篇: 2月份Web服务器份额:排名不变 仅Mi