View encapsulation, xib and stroryboard loading and use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.