如何在选择UITableView行时更改默认的蓝色

时间:2022-11-21 20:44:22

Duplicate:

can i use highlighted the table view cell without default blue color in objective c?

我可以使用突出显示表格视图单元格而没有目标c中的默认蓝色吗?

How can I change the default blue color when selecting the row of UITable?

如何在选择UITable行时更改默认的蓝色?

2 个解决方案

#1


UITableViewCellSelectionStyle is built in to Cocoa Touch and will give you a few choices. For more customization, you'll need to change your cell manually:

UITableViewCellSelectionStyle内置于Cocoa Touch,它将为您提供一些选择。要进行更多自定义,您需要手动更改单元格:

How do I set UITableViewCellSelectionStyle property to some custom color?

如何将UITableViewCellSelectionStyle属性设置为某种自定义颜色?

#2


in the delegate of the tableview, where you create the cell, you can custom it.

在tableview的委托中,您可以在其中创建单元格。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *customCellIdentifier = @"customCellIdentifier ";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourBackground.png"]] autorelease];
    }

    // configure the cell
}

#1


UITableViewCellSelectionStyle is built in to Cocoa Touch and will give you a few choices. For more customization, you'll need to change your cell manually:

UITableViewCellSelectionStyle内置于Cocoa Touch,它将为您提供一些选择。要进行更多自定义,您需要手动更改单元格:

How do I set UITableViewCellSelectionStyle property to some custom color?

如何将UITableViewCellSelectionStyle属性设置为某种自定义颜色?

#2


in the delegate of the tableview, where you create the cell, you can custom it.

在tableview的委托中,您可以在其中创建单元格。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *customCellIdentifier = @"customCellIdentifier ";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourBackground.png"]] autorelease];
    }

    // configure the cell
}