0

I have an empty ViewController. Programatically I'm setting back ground image.

- (void)setBackGroundImg:(NSString*) name {

    UIGraphicsBeginImageContext(self.view.frame.size);
    [[UIImage imageNamed:name] drawInRect:self.view.bounds];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.view.backgroundColor = [UIColor colorWithPatternImage:image];

}

Problem: I'm running app in simulator. Without rotation its looks like this.enter image description here

But when I rotate the simulator app looks like this enter image description here

Any idea how can i fix this issue.I'm working on Xcode 5 with auto layout ON. I see no way how to set constraints in empty ViewController

Marco
  • 6,692
  • 2
  • 27
  • 38
Omer Obaid
  • 416
  • 1
  • 6
  • 24

2 Answers2

0

If you want an image to rotate automatically when the device rotates, display the image inside a UIImageView instead of drawing the image manually. Check the docs for UIImageView.

bilobatum
  • 8,918
  • 6
  • 36
  • 50
0

just use 9-path, for example:

self.view.backgroundColor = [UIColor colorWithPatternImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
Bimawa
  • 3,535
  • 2
  • 25
  • 45