Skip to content

Instantly share code, notes, and snippets.

@heydona

heydona/gist:4568981

Last active Dec 11, 2015
Embed
What would you like to do?
Adding a new delete confirmation button
- (void)willTransitionToState:(UITableViewCellStateMask)state {
CGRect f;
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
if (!_deleteButton) {
_deleteButton = [MPButton buttonWithType:MPButtonTypeAlert withTitle:NSLocalizedString(@"Delete",@"Delete")];
[[_deleteButton titleLabel] setFont:[[UIFont buttonFont] changeFontSizeBy:-2]];
[_deleteButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_deleteButton];
}
f = RBRectCenterPositionY([_deleteButton frame], CGRectGetHeight([self frame]));
f.origin.x = CGRectGetWidth([self frame]);
[_deleteButton setFrame:f];
f.origin.x = CGRectGetMaxX([self frame]) - [UIScreen tableContentPadding] - f.size.width;
_isDeleting = NO;
} else {
[super willTransitionToState:state];
if (_deleteButton) {
f = [_deleteButton frame];
if (_isDeleting) {
alpha = 0.0f;
} else {
f.origin.x = CGRectGetWidth([self frame]);
}
}
}
if (_deleteButton) {
[UIView animateWithDuration:0.3f
animations:^{
[_deleteButton setFrame:f];
[_deleteButton setAlpha:alpha];
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment