iOS自定义UITableView单元格按钮
问题描述:
我想当用户滑动一个表格视图单元格时,显示多个编辑按钮(他默认是删除按钮)。是否可以在tableView:tableView editingStyleForRowAtIndexPath:
方法中放置自定义按钮?iOS自定义UITableView单元格按钮
答
将手势识别器添加到您的课堂并在其选择器中尝试下面的内容。
-(void)cellDidSwipeLeft:(UIGestureRecognizer *)_gestureRecognizer
{
if(_gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
CGPoint swipeLocation = [_gestureRecognizer locationInView:self.tableView];
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
UITableViewCell* swipedCell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:swipedIndexPath];
YourCustomBtn *Btn = (YourCustomBtn *)[swipedCell viewWithTag:999];
[self performAnimationOnObject:Btn forPoint:swipeLocation];
}
}
-(void)performAnimationOnObject:(id)view forPoint:(CGPoint)point
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.delegate = self;
animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(btn.superview.frame.size.width, btn.center.y)];
animation.toValue = [NSValue
valueWithCGPoint:CGPointMake(mainCleanFrame.origin.x, btn.center.y)];
animation.fillMode = kCAFillModeForwards;
btn.center = CGPointMake(btn.frame.origin.x, btn.center.y);
}
答
我创建了一个新库来实现swippable按钮,它支持多种转换和可扩展按钮,如iOS 8邮件应用程序。
https://github.com/MortimerGoro/MGSwipeTableCell
该库是与所有的不同的方法来创建一个UITableViewCell及其在iOS 5,iOS 6中,7的iOS和iOS 8.测试
+0
它将如何与自定义单元格一起工作? – KiranJasvanee
是能够兼容 –
你会如此善良,并告诉我如何? – Teo
你可以用编程方式创建一个按钮,而不是编辑样式 –