Search code examples
iphoneiosuiimageuibackgroundcolor

Background image not fit to the screen


Here in my app i used the background image size as 320 x 480,but in the end of the screen some portions not visible,here my code

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ibg.png"]];

Please help me to solve to make the image screen fit.. enter image description here


Solution

  • If the invisible portion has height equal to 50 pixel, then could you please try resize your image (ibg.png) to 320 x 430 using

    - (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
        UIGraphicsBeginImageContext(size);
        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return destImage;
    }
    

    after that

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ibg.png"]];
    

    should make it, hope it help, please give me a feedback, thanks.