Solved this by forcing layout before setting any layout-related properties like clipToBounds etc... The tricky part is where and when to call layoutIfNeeded
.
In my case, I have an UIButton with horizontal,top,and height constraints. Apparently on Xcode 8, my button's title went suddenly missing. Then weird enough the title appeared after I removed the height constraint. This behaviour indicates an issue probably within the view's layout cycle. I needed to have the height constraint so removing it wasn't really the solution. So I tried to call layoutIfNeeded
prior to setting the constraints but no effect.
I generate this button on viewDidLoad on a controller via an NSObject class which handles it. The solution for me was forcing a layoutIfNeeded
before calling the method that setUps the button.
- (void)viewDidLoad {
[super viewDidLoad];
[self.view layoutIfNeeded];
//editBooking - NSObject class where the button gets configured.
[_editBooking setUpViews];
}
Related issues: clipsToBounds causes UIImage to not display in iOS10 & XCode 8
Edit:
"I think the (0, 0, 1000, 1000) bound initialization is the new way
Xcode instanciates views from IB. Before Xcode8, views were created
with their configured size in the xib, then resized according to
screen just after. But now, there is no configured size in IB document
since the size depends on your device selection (at the bottom of the
screen)."
Reference: Since Xcode 8 and iOS10, views are not sized properly on viewDidLayoutSubviews
From Apple release notes:
Sending layoutIfNeeded to a view is not expected to move the view, but in earlier releases, if the view had translatesAutoresizingMaskIntoConstraints set to NO, and if it was being positioned by constraints, layoutIfNeeded would move the view to match the layout engine before sending layout to the subtree.
These changes correct this behavior, and the receiver’s position and usually its size won’t be affected by layoutIfNeeded.
Some existing code may be relying on this incorrect behavior that is now corrected. There is no behavior change for binaries linked before iOS 10, but when building on iOS 10 you may need to correct some situations by sending -layoutIfNeeded to a superview of the translatesAutoresizingMaskIntoConstraints view that was the previous receiver, or else positioning and sizing it before (or after, depending on your desired behavior) layoutIfNeeded.
Reference: iOS10 release notes