Xcode 如何在iOS 11上的UITableViewCell上自定义删除按钮

Xcode 如何在iOS 11上的UITableViewCell上自定义删除按钮,xcode,uitableview,Xcode,Uitableview,这是一段代码,可以在UITableViewCell delete按钮上显示一些自定义内容(颜色、图像),但当我在iOS 11上更新后,这段代码不起作用,我只使用了红色按钮,而不是自定义按钮。我如何理解苹果再次更改键“UITableViewCellDelete确认按钮”。也许你知道如何解决这个问题 - (UIView*)recursivelyFindConfirmationButtonInView:(UIView*)view { if (floor(NSFoundationVersionN

这是一段代码,可以在UITableViewCell delete按钮上显示一些自定义内容(颜色、图像),但当我在iOS 11上更新后,这段代码不起作用,我只使用了红色按钮,而不是自定义按钮。我如何理解苹果再次更改键“UITableViewCellDelete确认按钮”。也许你知道如何解决这个问题

- (UIView*)recursivelyFindConfirmationButtonInView:(UIView*)view
{
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
        // iOS 8+ code here
        for(UIView *subview in view.subviews) {

            if([NSStringFromClass([subview class]) rangeOfString:@"UITableViewCellActionButton"].location != NSNotFound)
                return subview;

            UIView *recursiveResult = [self recursivelyFindConfirmationButtonInView:subview];
            if(recursiveResult)
                return recursiveResult;
        }
    }

    else{
        // Pre iOS 8 code here
        for(UIView *subview in view.subviews) {
            if([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationButton"]) return subview;
            UIView *recursiveResult = [self recursivelyFindConfirmationButtonInView:subview];

            if(recursiveResult) return recursiveResult;

        }
    }
    return nil;

}

-(void)overrideConfirmationButtonColor
{

    dispatch_async(dispatch_get_main_queue(), ^{
        UIView *confirmationButton = [self recursivelyFindConfirmationButtonInView:self];
        if(confirmationButton)
        {
            self.buttonConfirm = [[UIButton alloc]initWithFrame:CGRectMake(13, 15, 90, 90)];
            self.buttonConfirmAnimation = [[UIImageView alloc]initWithFrame:CGRectMake(12, 15, 40, 40)];


            self.buttonConfirmAnimation.image = [UIImage imageNamed:@"heartWh"];

            confirmationButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"patternPlist@2x"]];

            [confirmationButton addSubview:self.buttonConfirmAnimation];

            [confirmationButton bringSubviewToFront:self.buttonConfirm];

        }
    });

}

我也有同样的问题——自从iOS 11.x以来,提议的解决方案不再有效。我注意到苹果不再使用UIButton作为删除按钮,而是使用名为
UITableViewCellEditControl
的UIView,该视图有两个子视图

这两个子视图实际上是UIImageView类型,一个带有删除图标的彩色图像,另一个带有灰色版本(我猜是某种效果/阴影)。您仍然可以修改这些图像,例如设置其颜色或完全更改图像

不幸的是,现在还有两个问题:

  • UITableViewCellEditControl
    也用于编辑样式为
    none
    的情况,即它可以是选择控件(空点/圆)。如果不使用UITableView本身的实际编辑样式,似乎不可能区分这两个用例

  • 点击delete控件后,它的image get将被Apple的原始控件替换。使用/设置UIImageView的高亮显示图像属性也没有帮助。似乎在
    UITableViewCellEditControl
    中有一些底层逻辑将隐式地将图像重置为原始图像