我有一个UITableView
为我的MasterView的SplitView应用程序。更改选择颜色 - TableView/SplitView
在选择任何行时,该行的颜色变为蓝色。我想将其更改为黑色或深灰色。我怎样才能做到这一点?
谢谢。
我有一个UITableView
为我的MasterView的SplitView应用程序。更改选择颜色 - TableView/SplitView
在选择任何行时,该行的颜色变为蓝色。我想将其更改为黑色或深灰色。我怎样才能做到这一点?
谢谢。
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *tableCell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (tableCell == nil) {
tableCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease] ;
[tableCell setSelectionStyle:UITableViewCellSelectionStyleGray];
}
}
或者你也可以试试这cellForRowAtIndexPath
if (indexPath.row == selectedIndex)
{
Cell.LblDynamicCell.textColor=[UIColor whiteColor];
Cell.LblBackView.backgroundColor=[UIColor Black];
}
//LblDynamicCell,LblBackView objects declare in cellViewController class
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedIndex = indexPath.row;
[self.ResultTbl reloadData];
}
以下枚举被定义为选择风格 -
typedef enum {
UITableViewCellSelectionStyleNone,
UITableViewCellSelectionStyleBlue,
UITableViewCellSelectionStyleGray
} UITableViewCellSelectionStyle;
因此,对于你的目的,你可以使用 - UITableViewCellSelectionStyleGray
您可以按如下方式更改所选单元格的颜色:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
UIImageView *theImageView = [[UIImageView alloc] initWithImage:[UIImage imageName:@"table_selected_cell.png"]];
self.selectedBackgroundView = theImageView;
[theImageView release];
}
改变你选择的颜色,其中table_selected_cell.png是你的颜色的2px图像。
什么是tableCell?我应该在哪里申报? – gamersoul
尝试更新的代码.. –
kz ..除了蓝色和灰色,还有其他任何颜色方案?像红色或黑色?我尝试使用代码行:“cell.selectionStyle = [UIColor colorWithWhite:0.2 alpha:1.0];”但它似乎并没有工作: -/ – gamersoul