Change the color of default red color delete button in UITableViewCell when swiping rows or click on edit button

前端 未结 5 1710
离开以前
离开以前 2020-11-28 04:43

I wanted to change the color of minus button and delete button of UITableViewCell when click on edit button or swiping UITableView rows. I have imp

5条回答
  •  眼角桃花
    2020-11-28 05:30

    fist time you call willTransitionToState in .m (customcell)

    - (void)willTransitionToState:(UITableViewCellStateMask)state{
        NSLog(@"EventTableCell willTransitionToState");
        [super willTransitionToState:state];
        [self overrideConfirmationButtonColor];
    }
    

    Check version iOS, it's here, i'm using iOS 7 - iOS8

    //at least iOS 8 code here
    - (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)
            {
                UIColor *color = UIColorFromRGB(0xFF7373);
                confirmationButton.backgroundColor = color;
    
            }
        });
    }
    

提交回复
热议问题