0

我正在构建一个 iphone 应用程序。

我有一个表格视图,我设置了一个背景图像,如下所示:

UIImageView * bg = [[UIImageView alloc] initWithImage:somebackgroundimage];
CGRect framebg = bg.frame;
framebg.origin.y = -64;
framebg.origin.x = 0;
framebg.size.width = 320;
framebg.size.height = 480;
[bg setFrame:framebg];
[_tblview setBackgroundView:bg];

无论我设置什么 framebg.size.width 或 framebg.size.height,图像总是出现扭曲或压缩,尺寸可能为 320 宽和 400 高。就好像该应用程序将强制调整图像大小以适应顶部导航栏和我的底部标签栏。

如何强制 tableview 背景图像为 320px 宽 x 480px 高?

此外,似乎 origin.y 和 origin.x 也没有得到尊重。

4

1 回答 1

1

我知道这个问题有点老了,但我想我会分享我能够用来解决类似问题的东西(setContentMode用于图像视图):

UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
[bg setContentMode:UIViewContentModeScaleAspectFit];
self.tableView.backgroundView = bg;

希望这可以帮助。

于 2013-01-15T03:23:32.770 回答