gpt4 book ai didi

iphone - UITableViewController 背景图片拉伸(stretch)

转载 作者:行者123 更新时间:2023-11-28 18:45:00 25 4
gpt4 key购买 nike

我正在尝试为 UITableViewController 设置背景图像。我有以下代码可以很好地设置背景,但图像本身被拉伸(stretch)到通常大小的两倍左右。

[[self view] setAutoresizesSubviews:NO];

UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default.png"]];

self.tableView.backgroundView = backgroundView;
self.tableView.backgroundColor = [UIColor clearColor];

[backgroundView release];

图片只有 640x960 像素。

我已经尝试手动设置 backgroundView 的框架,但它不会改变背景图像的大小。

谁能解释我哪里出错了?

非常感谢。

最佳答案

根据我的经验,你应该避免使用

[UIColor colorWithPatternImage: ... ];

因为它会导致为 Retina/低分辨率设备选择正确图像时出现一些问题。

尝试更像这样的东西:

UIImageView* bgView = [[[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"Default.png"]] autorelease];

[tableView.backgroundView addSubview:bgView];

还要确保你有两个 PNG:

  • Default.png - 320 x 480
  • 默认@2x.png = 640 x 960

关于iphone - UITableViewController 背景图片拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5588134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com