I saw other posts but still can’t get my background image to scale correctly. I use a UIView to set a background image because i need the background image to tile vertically. I set the frame of the UIView to be the same size as my pixel width and height of the png, but the image gets offset and scaled incorrectly. Could it be because the image has some transparent pixels? I tried the following:
_view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
_view.opaque = NO;
_view.contentMode = UIViewContentModeScaleAspectFit;
//_view.layer.contentsGravity = kCAGravityTop;
You might find it easier to just make a subclass of
UIView. In the subclass, overridedrawRect:to draw your image usingdrawAsPatternInRect:. That method will fill the view by tiling the image: