A. View Package:
Code implementation:
-(Instancetype) init
{
if (self = [super init]) {
1. Add a Uiimageview object to display a picture of the item
Uiimageview *iconview = [[Uiimageview alloc] init];
[Self addsubview:iconview];
Self.iconview = IconView;
2. Add Uilabel object to display the name of the product
UILabel *titlelabel = [[UILabel alloc] init];
Titlelabel.textalignment = Nstextalignmentcenter;
[Self Addsubview:titlelabel];
Self.titlelabel = Titlelabel;
}
return self;
}
-(void) layoutsubviews
{
[Super Layoutsubviews];
1. Remove the width and height of the current control
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height;
2. Adjust the frame of the child control
Self.iconView.frame = CGRectMake (0, 0, width, width);
Self.titleLabel.frame = CGRectMake (0, Width, width, height-width);
}
Two. Comparison of Xib and Stroyboard
Load Xib
Three. Use MVC's ideas to group code
View encapsulation, xib and stroryboard loading and use