【问题标题】:Change color of circular edit button in UITableViewCell更改 UITableViewCell 中圆形编辑按钮的颜色
【发布时间】:2016-07-07 22:23:59
【问题描述】:

如何更改表格视图单元格中删除按钮的图像?

我的意思是左侧的红色圆圈按钮:

【问题讨论】:

标签: ios uitableview cocoa-touch


【解决方案1】:

在您的 UITableViewCell 子类中覆盖以下内容:

- (void)willTransitionToState:(UITableViewCellStateMask)state
{
    [super willTransitionToState:state];
    if(state == UITableViewCellStateShowingEditControlMask)
    {
        for (UIView *v in self.subviews) {
            if ([NSStringFromClass([v class]) isEqualToString:@"UITableViewCellEditControl"]) {
                UIImageView *customButton = [[UIImageView alloc]initWithFrame:v.bounds];
                [customButton setImage:[UIImage imageNamed:@"delete.png"]];
                [v addSubview:customButton];
                [v bringSubviewToFront:customButton];
            }
        }
    }
}

您可以使用子视图和状态来获得您喜欢的结果。

【讨论】:

  • 这个方法没有被调用:(
  • @AndreyEvstratenko,我在提交之前已经尝试过这段代码。请确保您有一个 UITableViewCell 子类和其中的此方法,并且您的表在 cellForRowAtIndexPath 中返回该类型的单元格
  • 噢噢……对不起!我发现了一个错误!)
  • 当表格视图改变其状态时调用此方法,例如从或到编辑状态。确保你打电话给[tableView setEditing:YES]
猜你喜欢
  • 1970-01-01
  • 2021-02-15
  • 2014-11-05
  • 2019-01-03
  • 2013-12-15
  • 1970-01-01
  • 2016-12-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多