Hello I have a UIImageView set as my background in a UITableView. Looks nice in portrait. I would like the cells to rotate, which they do, however, I want the image background to not rotate.
When it rotates its resized smaller, with black bars around it.
This is the code that partially gets what I want accomplished.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
imageView.contentMode = UIViewContentModeScaleAspectFit;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = imageView;
I was hoping there was some code that would make the background exempt from rotating. What do you guys think?
You need to autoresize the image view
UIImage *originalImage = [... whatever ...]; UIImage *imageToDisplay = [UIImage imageWithCGImage:[originalImage CGImage] scale:1.0 orientation: UIImageOrientationUp]; UIImageView *imageView = [[UIImageView alloc] init]; imageview.autoresizingMask= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; //or however you need to mask imageView.contentMode = UIViewContentModeScaleAspectFit; self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.backgroundView = imageView;
Hope this Helps !!!