Reputation: 9994
I know that how I can set image for the cells in my static UITavleView programmatically:
cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"image1.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];
I could set the background color, but not the image. Is it possible to set it from interface builder?
Upvotes: 1
Views: 2077
Reputation: 9977
It is possible by connecting the backgroundView outlet of the tableViewCell (with another view in the nib file). But you cannot make stretchable images within the interface builder..
Upvotes: 0
Reputation: 2556
Create a new user interface Xib file. Delete the initial view. Drag and drop your uitableviewcell into the builder. Customize... Then put this in viewDidLoad:
UINib *cellNib = [UINib nibWithNibName:@"pizzaCell" bundle:[NSBundle mainBundle]];
[self.tableView registerNib:cellNib
forCellWithReuseIdentifier:@"pizzaCell"];
Then in cellForRowAtIndexPath do this:
static NSString *cellIdent = @"pizzaCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
Now you have your nib cell. If you want to get references to the views you added to the cell the way I do it is to give em tags and call viewWithTag on the cell.
You might also just be seeking:
cell.contentView.imageView.image = [UIImage imageNamed:@"PizzaImage"];
Not sure how much you want to customize
Upvotes: 2