一個(gè)空間看不見(jiàn)可能
-看度和高度其實(shí)為0
-位置不對(duì)(比如是負(fù)數(shù)或者超大的數(shù)字,超出屏幕)
-hidden==YES
-alpha<=0.01
-沒(méi)有設(shè)置背景色,沒(méi)有設(shè)置內(nèi)容
-文字顏色和背景色一樣
一般一個(gè)view比較多,一般會(huì)自定義一個(gè)人view
封裝過(guò)程
加進(jìn)去
layoutSubViews 子空間跟著父控件變化
模型屬性 重寫(xiě)set方法 傳入模型屬性
#import "XMGShopView.h"
#import"XMGShop.h"
@interface XMGShopView()
/** 商品名稱 */
@property(nonatomic,strong)UILabel * namelabel ;
/** 商品圖片
*/
@property(nonatomic,strong)UIImageView * iconView ;
@end
@implementation XMGShopView
- (instancetype)init
{
if (self== [super init]) {
// 添加圖片
UIImageView *iconView = [[UIImageView alloc] init];
iconView.backgroundColor = [UIColor blueColor];
[self addSubview:iconView];
self.iconView=iconView;
// 添加文字
UILabel *namelabel = [[UILabel alloc] init];
namelabel.font = [UIFont systemFontOfSize:11];
namelabel.textAlignment = NSTextAlignmentCenter;
namelabel.backgroundColor=[UIColor orangeColor];
[self addSubview:namelabel];
self.namelabel=namelabel;
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
CGFloat shopH=self.frame.size.height;
CGFloat shopW=self.frame.size.width;
self.iconView.frame=CGRectMake(0, 0, shopH, shopH);
self.namelabel.frame=CGRectMake(0, shopW, shopW, shopH-shopW);
}
-(void)setShop:(XMGShop *)shop
{
_shop=shop;
self.namelabel.text=shop.name;
self.iconView.image=[UIImage imageNamed:shop.icon];
}
@end
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。