自定义UITableViewRowAction按钮 [英] Custom UITableViewRowAction button
本文介绍了自定义UITableViewRowAction按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为uitableviewrowaction按钮设置顶部和底部约束
I want to set top and bottom constraint for uitableviewrowaction button
这是我的代码
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
deleteAction.backgroundColor = [UIColor redColor];
return @[deleteAction];
}
就像这样,我添加了删除按钮.在tableviewCell
中,我添加了一个UIView
,它具有顶部和底部约束.我希望删除按钮与UITableviewCell
中的视图匹配.
Like this I've added delete button. In tableviewCell
I've added one UIView
it has top and bottom constraints. I want the delete button to match with my view in UITableviewCell
.
推荐答案
您可以在自定义uitableviewcell类中设置删除按钮框架
you can set delete button frame in your custom uitableviewcell class
像这样
-(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;
}
使用 didTransitionToState 方法:)
这篇关于自定义UITableViewRowAction按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文