简体   繁体   中英

Change to custom background when a cell is highlighted

How can I change the background of a custom cell when a it is selected ?

Thanks, Niels

if (cell == nil) {

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    UIView *v = [[[UIView alloc] init] autorelease];
    v.backgroundColor = [UIColor blueColor];
    cell.selectedBackgroundView = v;

use this

You need to subclass UITableViewCell , and override the following methods:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;

You can change the cell's background image there.

The cell's selectionStyle property allows for some very basic customization, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM