iOS loading xib encounters a pit

Source: Internet
Author: User

Storyboard, personally think is a good thing, but everything to do it always feel messy. Personal preference pulls complex local controls (such as custom Collectionviewcell) in the Xib file.

In the development process encountered a lot of pits, the memory is: Xib parts (such as button) the effect of setting rounded corners, the loaded xib cannot resize size.

First question: The setting code for the fillet:

View.layer.cornerRadius = VIEW.FRAME.SIZE.HEIGHT/2;

Using AutoLayout, you need to be aware of where the call is: (because AutoLayout will recalculate the frame, the frame where the child control is called is correct)

-(void) viewdidlayoutsubviews;

Well, what if xib? In the following function, write the effect of the child control you need to reach.

-layoutsubviews;

The following function is called by the owner of the Xib, and the following function departs Layoutsubviews

[Xib layoutifneeded]

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

The second question: you set the size of the xib, but the interface Xib still stubbornly shows the size of its 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;}


iOS loading xib encounters a pit

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.