Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UIImageView in background programmatically

i have a class with no .xib file, and i want to set the background with a UIImageView with a .png file i have in the resources, i try this:

UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]];
[[self view] setBackgroundColor:background];
[background release];

this work, but the image is zoomed in and loses a lot of quality, instead in another class with xib file i set a UIImageView in background by Interface Builder and the image is perfetct, i wanna know how i can set the UIImageView in background as i do in interface builder.

like image 945
Piero Avatar asked May 03 '11 09:05

Piero


1 Answers

Sorry if i forgot to write that my class is a UITableViewController, this is the solution:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[imageView setImage:[UIImage imageNamed:@"background.png"]];
self.tableView.backgroundView = imageView;
[imageView release];

thanks to all!

like image 164
Piero Avatar answered Sep 18 '22 00:09

Piero