【问题标题】:UITableView - Highlighting Selected Cell [iOS]UITableView - 突出显示选定的单元格 [iOS]
【发布时间】:2011-08-29 08:25:25
【问题描述】:

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

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

我已经根据自己的需要对其进行了定制,它看起来很棒。但是,当我选择一行时,它会通过将整个内容更改为蓝色来突出显示该行。这个高亮覆盖了整个单元格并覆盖了内容,有效地制作了一个看起来很讨厌的蓝色大框。我已经尝试了

的替代突出显示选项
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.selectionStyle = UITableViewCellSelectionStyleGray;

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

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

谢谢

【问题讨论】:

    标签: iphone objective-c xcode uitableview ios4


    【解决方案1】:

    可能是因为您的示例代码正在设置:

    artistLabel.highlightedTextColor = [UIColor clearColor];.

    它会导致artistLabel的文本颜色在高亮时变为透明。

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

    [UIColor whiteColor]

    【讨论】:

    • 我真是个白痴,谢谢。简单的答案,效果很好。谢谢
    • 不客气。如果您认为此答案有用,请投票并将其选为正确答案。
    • 我总是这样。我有 100% 的问题。再次感谢。
    • :) 也谢谢你。很难将这个比率保持在 100%,这太不可思议了。
    【解决方案2】:

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

    【讨论】:

    • 我还建议调用 [cell setSelectionStyle: UITableViewCellSelectionStyleNone] 以防止单元格在被选中时出现在其周边的白色矩形中。
    【解决方案3】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-06
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多