开发者

Adding backgroundimage to my app

I am using this code to add a background image to my tableview

myTable.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]] autorelease];

on the internet they say this code works, but it's not working 开发者_开发百科for me can someone help me please?


if its a UITableViewController, as I believe it is, do this:

[myTable setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];

or you can do (on a non-table view controller)

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];

or on viewDidLoad you can do:

UIImageView *backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]] autorelease];
[self.view addSubview:backgroundView];

but thats a bit messy - I prefer to use setBackgroundColor:


The problem is that backgroundview for tableview is a UIView, not a UIImage. So you need to create a view, easiest way is to use a UIImageView. For example this would put your splash screen image as the background view for the table in a UITableViewController...

    UIImage *backImage = [UIImage imageNamed:@"default.png"];
UIImageView *backImageView = [[UIImageView alloc] initWithImage:backImage];
self.tableView.backgroundView = backImageView;

The methods mentioned above are pre the introduction of tableview property backgroundview in 3.2

edit - dear god I was obviously having a coffee deficit today :) The op is indeed using a UIImageView! The only thing I can think is that he is targeting a pre 3.2 platform...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜