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;}