繁体   English   中英

UITableView - 突出显示所选单元格[iOS]

[英]UITableView - Highlighting Selected Cell [iOS]

我已经创建了一个自定义TableCell的UITableView,通常遵循本教程;

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

我根据自己的需求定制了它,看起来很棒。 但是,当我选择一行时,它会通过将整个事物更改为蓝色来突出显示该行。 这个亮点涵盖整个单元格并覆盖内容,有效地制作一个看起来很讨厌的大蓝盒子。 我已经尝试了备用突出显示选项

cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.selectionStyle = UITableViewCellSelectionStyleGray;

显然,如果选择为灰色,则会出现相同的行为,但会出现灰色的丑陋框。 “无”是最好的选择,但不能为我的用户提供良好的体验,因为我想表明他们已经选择了那一行。

任何人都可以建议一种方法来显示该行是高亮的,但仍然显示下面的文字? 半透明度?

谢谢

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

artistLabel.highlightedTextColor = [UIColor clearColor];

当高亮显示时,它会使artistLabel的文字颜色变得透明。

因为您可以为标签的highlightTextColor属性设置自己的颜色,例如:

[UIColor whiteColor]

UITableView Cell选择了Color

请享用...

// 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];

你可以使用自己的自定义视图来选择

在这里,我有绿色的颜色。你可以改变你想要的任何定制。

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];

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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