CBredlow
CBredlow

Reputation: 2840

UIView background image not rotating

I've got an app that has two different background images. The one selected is determined by the orientation. When I start out, I check self.interfaceOrientation, and then go and pick the proper image. However, whenever the view opens, part of the image repeats instead of stretching. I saw a previous answer applying autoresizing masks to an imageview, but there is no imageview that I'm currently using.

Inside the loadView method:

if(self.interfaceOrientation==UIInterfaceOrientationPortrait ||self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
  [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"portrait"]]];
}else{
  [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"landscape"]]];
}

Upvotes: 0

Views: 690

Answers (1)

CBredlow
CBredlow

Reputation: 2840

As rishi had pointed out, the issue was caused by the colorWithPatternImage method. What I did to resolve this was to set the background of the view to be a specified image.

UIImageView* bgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed: @"foo.png"]];
[self.view addSubview: bgView];

I also added in flexible width and height so that it would rotate properly.

Upvotes: 1

Related Questions