Share on Google+Share on Google+

UITableViewCell selectedBackgroundView

Advertisement
In any iphone UItable based application we have lots of options to customize the look and feel of Table View. For example we can either add color or background image to cellView.

UITableViewCell selectedBackgroundView

This example exhibits how to add cell BackgroundImage in UITable based applications.

In any iphone UItable based application we have lots of options to customize the look and feel of Table View. For example we can either add color or background image to cellView. By default cell take the nil value or plain style, you can also write is as "UITableViewStylePlain" and if you wanted to add a background image to cell "selectedBackgroundView" will be written.

That will add the background image on cell as subview on selected cell. In this example we are creating a Navigation based application that has a array to hold the list of values, which will be displayed on the table View.

Now, to add the background Image to cell just find the given code.

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Home.png"]] autorelease];
}

// Configure the cell.
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

return cell;
}

On running the application you'll see the following output.




Download Code

Advertisements

Advertisement

Posted on: May 5, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.