Custom UITableViewRowAction button

后端 未结 3 914
野性不改
野性不改 2021-01-15 03:34

I want to set top and bottom constraint for uitableviewrowaction button

Here\'s my code

- (NSArray *)tableView:(UITableView *)tableView editActionsFo         


        
相关标签:
3条回答
  • 2021-01-15 04:10

    A little more about Balkaran's answer... The delete button is a custom private class, but using the String(describing:) method, you can be reasonably sure you can get ahold of it.
    Also, I was surprised to find that didTransition fires as soon as you start changing the state, not when the state is done changing.

    An updated version of @balkaran's code in Swift 3:

    override func didTransition(to state: UITableViewCellStateMask) {
        super.willTransition(to: state)
        if state == .showingDeleteConfirmationMask {
            let deleteButton: UIView? = subviews.first(where: { (aView) -> Bool in
                return String(describing: aView).contains("Delete")
    
            })
            if deleteButton != nil {
                deleteButton?.frame.size.height = 50.0
            }
    
    0 讨论(0)
  • 2021-01-15 04:13
        super.willTransitionToState(state)
        if state == .ShowingDeleteConfirmationMask
        {
           let deleteButton: UIView? = subviews[0]
    
            if deleteButton != nil {
                var frame: CGRect? = deleteButton?.frame
                frame?.origin.y = 9
                frame?.origin.x = 10
                frame?.size.height = (frame?.size.height)! - 14
                deleteButton?.frame = frame!
            }
        }
    
    0 讨论(0)
  • 2021-01-15 04:14

    you can set delete button frame in your custom uitableviewcell class

    like this

     -(void)didTransitionToState:(UITableViewCellStateMask)state
    {
        [super didTransitionToState:state];
        if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask)
        {
    
            UIView *deleteButton = [self deleteButtonSubview:self];
            if (deleteButton)
            {
                CGRect frame = deleteButton.frame;
                frame.origin.y = 4;
                frame.size.height = frame.size.height-8;
                /*
                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                {
    
                    frame.size.height = 62; //vikram singh 2/1/2015
                    frame.size.width = 80;
    
                }
                else
                {
                    frame.size.height = 52; //vikram singh 2/1/2015
                    frame.size.width = 80;
    
                }
                 */
                deleteButton.frame = frame;
    
            }
        }
    }
    
    - (UIView *)deleteButtonSubview:(UIView *)view
    {
        if ([NSStringFromClass([view class]) rangeOfString:@"Delete"].location != NSNotFound) {
            return view;
        }
        for (UIView *subview in view.subviews) {
            UIView *deleteButton = [self deleteButtonSubview:subview];
            [deleteButton setBackgroundColor:[UIColor whiteColor]];
            if (deleteButton) {
    
                return deleteButton;
            }
        }
        return nil;
    }
    

    use didTransitionToState methods :)

    0 讨论(0)
提交回复
热议问题