开发者

UITableViewController background image stretched

I'm trying to set the background image for a UITableViewController. I've got the following code which does set the background fine, but the image itself is being stretched to about twice the usual size.

[[self view] setAutoresizesSubviews:NO];

UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.frame];
backgroundView.backgroundColor = [UIColor colorWithPa开发者_如何学PythontternImage:[UIImage imageNamed:@"Default.png"]];

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

[backgroundView release];

The image is only 640x960 pixels.

I've tried manually setting the frame of the backgroundView but it doesn't change the size of the background image.

Can anyone explain where I'm going wrong?

Many thanks.


In my expirience, you should avoid using

[UIColor colorWithPatternImage: ... ];

as it leads to some problems with picking the right image for Retina/Low-Res devices.

Try something more like this:

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

[tableView.backgroundView addSubview:bgView];

Also make sure you have two PNGs:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜