UITableViewCell selectedBackgroundView


 

UITableViewCell selectedBackgroundView

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.

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

Ads