Pranoy C Pranoy C - 2 months ago 138
iOS Question

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.

Answer

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.

Comments