Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 10 GM with xcode 8 GM causes views to disappear due to roundedCorners & clipsToBounds

I tested my app with iOS 10 Beta 7 and Xcode 8 beta and everything worked fine. However just a few minutes ago I installed the now available GM releases of both and faced a weird issue.

I am using custom table view cells in my app and in my custom cell's I am using cornerRadius and clipsToBounds to create rounded views.

- (void)awakeFromNib {     [super awakeFromNib];     self.tag2label.layer.cornerRadius=self.tag2label.frame.size.height/2;     self.tag2label.clipsToBounds=YES; } 

This looked okay before however in the new GM releases all the views which had the rounded corners disappeared. This happened to UIView, UILabels and UIButtons.

I solved this below.

like image 422
sudoExclaimationExclaimation Avatar asked Sep 07 '16 22:09

sudoExclaimationExclaimation


2 Answers

I am not sure if this is a new requirement, but I solved this by adding [self layoutIfNeeded]; before doing any cornerRadius stuff. So my new custom awakeFromNib looks like this:

- (void)awakeFromNib {     [super awakeFromNib];     [self layoutIfNeeded];     self.tag2label.layer.cornerRadius=self.tag2label.frame.size.height/2;     self.tag2label.clipsToBounds=YES; } 

Now they all appear fine.

like image 172
sudoExclaimationExclaimation Avatar answered Sep 19 '22 08:09

sudoExclaimationExclaimation


To fix invisible views with cornerRadius=height/2 create category UIView+LayoutFix

In file UIView+LayoutFix.m add code:

- (void)awakeFromNib {     [super awakeFromNib];     [self layoutIfNeeded]; } 

add category to YourProject.PCH file.

It will works only if you used [super awakeFromNib] in your views :

MyView.m

- (void)awakeFromNib {     [super awakeFromNib];     ... } 
like image 37
ealee Avatar answered Sep 21 '22 08:09

ealee