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

10
  • Pattern image will replicate itself. What are you trying to achieve? Maybe it can be done in other way.
    – vokilam
    Commented Feb 10, 2014 at 10:12
  • @vokilam i wanna get rid of this repetition first
    – Omer Obaid
    Commented Feb 10, 2014 at 10:16
  • and is this possible when i rotate the simulator image also rotate it self?
    – Omer Obaid
    Commented Feb 10, 2014 at 10:21
  • what do you mean rotate itself?
    – vokilam
    Commented Feb 10, 2014 at 10:25
  • @vokilam you can see in picture, image not rotating when simulator rotate
    – Omer Obaid
    Commented Feb 10, 2014 at 10:26

2 Answers 2

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.

0

just use 9-path, for example:

self.view.backgroundColor = [UIColor colorWithPatternImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.