I have a menu like so:
The normal (unselected) state for each cell is an image, the selected state is also an image (that looks like the default blue one). However, I'd like to add an additional third image, so that when the user selects a cell, it briefly changes to that third color before going blue (selected).
This is my code:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setBackgroundColor:[UIColor clearColor]];
NSString *cellIdentifier = @"MenuItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
UIImage *cellBackgroundNormal = [UIImage imageNamed:@"cell_menu_normal"];
UIImage *cellBackgroundSelected = [UIImage imageNamed:@"cell_menu_selected"];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:cellBackgroundNormal];
UIImageView *cellBackgroundSelectedView = [[UIImageView alloc] initWithImage:cellBackgroundSelected];
cell.backgroundView = cellBackgroundView;
cell.selectedBackgroundView = cellBackgroundSelectedView;
[cell.textLabel setBackgroundColor:[UIColor clearColor]];
[cell.textLabel setTextColor:[UIColor whiteColor]];
[cell.textLabel setFont:[UIFont boldSystemFontOfSize:17.0]];
cell.textLabel.text = [self.menuItems objectAtIndex:indexPath.row];
return cell;
}
As you can see, I only have two states as of now. I don't see how I can introduce some sort of cell.hoveredBackgroundView
for the third image. If anyone can help me implement this, I'd really appreciate it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…