2011-08-29 75 views
10

我已经创建了一个UITableView并自定义TableCell,通常按照本教程进行;UITableView - 突出显示所选单元格[iOS]

http://www.theappcodeblog.com/?p=353

我把它定制,以我的需求和它看起来棒极了。但是,当我选择一行时,通过将整个事物更改为蓝色来突出显示该行。这个亮点覆盖了整个单元格并覆盖了内容,实际上制作了一个看起来很讨厌的大蓝盒子。如果选择灰我都试过的

显然备用突出显示选项,同样的行为发生,但以灰色丑陋箱子。 '无'是一分钟的理想选择,但不会为用户提供良好的体验,因为我想说明他们选择了该行。

任何人都可以提出一种方法来显示该行是highligted,但仍然显示下面的文本?半透明?

感谢

回答

11

也许是因为你的代码示例设置:

artistLabel.highlightedTextColor = [UIColor clearColor];

这会导致artistLabel的文字颜色在突出显示时变为透明。

原因,你可以将自己的颜色设为您的标签highlightedTextColor属性,例如:

[UIColor whiteColor]

+0

我什么绝对的白痴,谢谢。简单的答案,完美的工作。谢谢 –

+1

不客气。如果你认为这个答案很有用,那么投票并选择它作为正确的答案将非常感激。 – xuzhe

+0

我总是这样做。我有100%提出非常问题,我问。再次感谢。 –

4

u可以使用乌尔自己的自定义视图选择

这里我有绿色视图像这样你可以改变任何你想要的定制。

if (cell == nil) { 

    cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero 
            reuseIdentifier: CellIdentifier] autorelease]; 


    UIView *selectionView = [[UIView alloc]initWithFrame:cell.bounds]; 

    [selectionView setBackgroundColor:[UIColor greenColor]]; 

    cell.selectedBackgroundView = selectionView; 


    [selectionView release]; 

} 
8

的UITableView单元格中所选颜色

享受...

// Image 
UIImage *selectionBackground = [UIImage imageNamed:@"g7.png"]; 
UIImageView *bgview=[[UIImageView alloc] initWithImage:selectionBackground]; 
cell.selectedBackgroundView=bgview; 
[bgview release]; 

// Color 
UIView *bgColorView = [[UIView alloc] init]; 
[bgColorView setBackgroundColor:[UIColor brownColor]]; 
[cell setSelectedBackgroundView:bgColorView]; 
[bgColorView release]; 
+0

很酷。颜色在iOS 7中可用。 – Tom

+0

我也建议调用[cell setSelectionStyle:UITableViewCellSelectionStyleNone],它在选中时防止单元格从其周界上的白色矩形。 –

相关问题