开发者

UITableView, select cell with colour different than blue?

开发者 https://www.devze.com 2023-03-31 11:34 出处:网络
I\'ve got a table view, how can I select a cell with different colour? Or how can I set the image of selection? thank开发者_运维问答sYou can easily change the cells selection style to gray:

I've got a table view, how can I select a cell with different colour? Or how can I set the image of selection? thank开发者_运维问答s


You can easily change the cells selection style to gray:

[myTableView setSelectionStyle: UITableViewCellSelectionStyleGray];

Or you can change the contentView's backgroundColor in the willDisplayCell delegate:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor redColor];
}

Another way would be to create a custom cell and change the color of the Background.


UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgColorView];
[bgColorView release];

Presumably you could do the same with a UIImageView as well

UIImageView *bgImageView = [[UIImageView imageNamed:@"Your Image"];
[cell setSelectedBackgroundView:bgImageView];
[bgImageView release];
0

精彩评论

暂无评论...
验证码 换一张
取 消