【问题标题】:Disable highlight button in uitableviewcell when select row选择行时禁用uitableviewcell中的突出显示按钮
【发布时间】:2015-08-03 16:32:28
【问题描述】:

我有自定义 UITableViewCell 和里面的两个按钮。当我选择行时,按钮的背景会更改为与所选行的背景相同的颜色,并且按钮的边框会消失。

如何在选择行时禁用更改按钮的边框/背景颜色?

感谢回复

【问题讨论】:

    标签: ios objective-c uitableview cocoa-touch


    【解决方案1】:

    1) 创建一个 UIView 并分配所需的背景颜色。 2) 将 UIView 渲染为 UIImage 3) 将按钮的 backgroundImage 设置为所需的状态。

    UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    colorView.backgroundColor = color;
    
    UIGraphicsBeginImageContext(colorView.bounds.size);
    [colorView.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    [button setBackgroundImage:colorImage forState: UIControlStateHighlighted];
    

    【讨论】:

      【解决方案2】:

      我为我的单元格使用清晰的背景视图并禁用行的选择颜色来实现这一点,但我需要那样做。不知道它是否适合你的需要,但你可以试试这个:

      UIView *selectedView = [[UIView alloc] initWithFrame:cell.bounds];
      selectedView.backgroundColor = [UIColor clearColor];
      cell.selectedBackgroundView = selectedView;
      cell.selectionStyle = UITableViewCellSelectionStyleNone;
      

      希望这会有所帮助。

      也请查看此线程:Why do all backgrounds disappear on UITableViewCell select?

      【讨论】:

        猜你喜欢
        • 2019-03-02
        • 1970-01-01
        • 1970-01-01
        • 2016-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-31
        相关资源
        最近更新 更多