Reputation: 1921
how to set custom color of table row when it is clicked...
i mean i don't want that blue color which appear by Default....
Upvotes: 1
Views: 418
Reputation: 2986
Make your own subclass of UITableViewCell. Overwrite the method -(void)setSelected:(BOOL)selected
Something like this:
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
if (selected) {
self.backgroundColor = [UIColor greenColor];
} else {
self.backgroundColor = [UIColor whiteColor];
}
}
Upvotes: 1
Reputation: 90117
To get whatever color you want, you have to replace the selectedBackgroundView with your own UIView.
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellID";
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIView *selectedBackground = [[[UIView alloc] init] autorelease];
selectedBackground.backgroundColor = [UIColor magentaColor];
cell.selectedBackgroundView = selectedBackground;
}
// configure cell
return cell;
}
Upvotes: 2
Reputation: 2241
you can set the tableView cell property
cell.selectionStyle = UITableViewCellSelectionStyleGray;
Upvotes: 1