I have a UIImageView subclass which contains a load of rendering code to render images. This class uses IBInspectable to set the values required through IB. Before AutoLayout this was working great like so
But I found when using this component with Size Classes in IB the rendered image is no longer right. Aaah, The frame size is not right. I have to resort to this hack
To get the image after the frame has been set properly. This isn't great as you can see the screen for a fraction of a second before the image is rendered.
So the question is, in a UIView subclass, what method is called as Autolayout is updating the view?
I have tried layoutSubviews, drawrect:, layoutMarginsDidChange, setFrame:, didMoveToSuperview... These are either not called or called before the final frame is set.
So what am I missing? What method is called on the UIView after each autolayout pass?
Code:
- (void) awakeFromNib {
UIImage *image = [self MyCoolImageRenderWithSize:self.frame.size];
self.image = image;
}
But I found when using this component with Size Classes in IB the rendered image is no longer right. Aaah, The frame size is not right. I have to resort to this hack
Code:
- (void) awakeFromNib {
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [self MyCoolImageRenderWithSize:self.frame.size];
self.image = image;
});
}
To get the image after the frame has been set properly. This isn't great as you can see the screen for a fraction of a second before the image is rendered.
So the question is, in a UIView subclass, what method is called as Autolayout is updating the view?
I have tried layoutSubviews, drawrect:, layoutMarginsDidChange, setFrame:, didMoveToSuperview... These are either not called or called before the final frame is set.
So what am I missing? What method is called on the UIView after each autolayout pass?