In each of my xibs it asked me what default device do I want to use. I chose iPhone 6 and updated the frames to the suggested ones. Now, any view that was affected in the viewWill or viewDidLayoutSubviews is messed up. They all have frames of CGRect(0, 0, 1000, 1000)
.
Here's my code:
self.headImage.layer.cornerRadius = ceilf(CGRectGetWidth(self.headImage.frame)/2);
self.headImage.layer.masksToBounds = YES;
Wondering what's up with this and whether there is a solution. Thanks
I resolved my issue by calling
myOwnView.layoutIfNeeded()
before getting the myOwnView.frame
If even viewDidLayoutSubviews gives you the wrong frame - calling layoutIfNeeded on layoutSubviews can do the trick!
override func layoutSubviews() {
super.layoutSubviews()
yourView.layoutIfNeeded()
setGradientForYourView()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With