当前位置: 动力学知识库 > 问答 > 编程问答 >

iOS UIImageView as UITableView background, prevent rotation

问题描述:

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?

Thanks

网友答案:

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 !!!

分享给朋友:
您可能感兴趣的文章:
随机阅读: