why is the image I’m trying to render in a custom UIView not being fit into window area to scale?
The code below is from a custom class that inherits from UIView. This view has been placed onto the main view in an XIB file, such that it’s not taking up the whole screen.
Also note I tried using both “self.window.frame” as well as “self.frame” as I wasn’t such which one to use. They both given different renderings however neither is one where the image is scaled correct.
Also I’m really after the “Scale To Fit” type of scaling, however I’m not sure how you would get this mode when using a “drawInRect” either?
- (void)drawRect:(CGRect)rect
{
// Drawing code
UIImage *altimeterImage = [UIImage imageNamed:@"Atimeter4.png"];
[altimeterImage drawInRect:self.window.frame];
}
Neither did the following work too:
- (void)drawRect:(CGRect)rect
{
// Drawing code
UIImage *altimeterImage = [UIImage imageNamed:@"Atimeter4.png"];
[altimeterImage drawInRect:self.frame];
}
Use the
boundsproperty. It will give you the rect in the view’s coordinate space.frameis the coordinates in its parent’s coordinate space so it will not work.Normally you would expect
rectparameter passed todrawRect:method to be equivalent to theboundsproperty but it always won’t be so it would be incorrect to rely on it.