Difficulties in loading xib on ios

Source: Internet
Author: User

Difficulties in loading xib on ios

Storyboard, I personally think it is a good thing, but everything is always messy. Personal preferences: Pull complicated local controls (such as custom collectionviewcell) in the xib file.

There were a lot of pitfalls in the development process, but I still remember that the effect of setting rounded corners for parts (such as buttons) in xib is incorrect; the size of loaded xib cannot be resize.

The first problem is the code for setting the rounded corner:

 

view.layer.cornerRadius = view.frame.size.height / 2;

 

When autolayout is used, pay attention to the calling points: (because autolayout recalculates the frame, it is correct to call the frame of the Child control here)

 

 

- (void)viewDidLayoutSubviews;

 

Okay. What if xib? In the following function, write the effect of the Child control you want to achieve.

 

 

-layoutSubviews;

 

The owner of the xib calls the following functions. The following functions start with layoutSubviews.

 

 

[xib layoutIfNeeded]

----------- Gorgeous split line ----------------

 

The second problem: You have set the size of the xib, but the page shows the size of the xib. Swollen.

 

- (void)awakeFromNib {    [super awakeFromNib];    //solve UICollectionViewCell subviews do not resize    self.contentView.autoresizingMask =        //UIViewAutoresizingFlexibleLeftMargin |        UIViewAutoresizingFlexibleWidth |        //UIViewAutoresizingFlexibleRightMargin |        //UIViewAutoresizingFlexibleTopMargin |        UIViewAutoresizingFlexibleHeight        //UIViewAutoresizingFlexibleBottomMargin    ;    self.contentView.translatesAutoresizingMaskIntoConstraints = YES;}


 

Related Article

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.