测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2014年12月 |
由 Massimiliano Bigatti 维护。
一个自定义的 UITableViewCell
,支持滑动手势以显示按钮或其他视图的自定义菜单。它支持
UIView
,用作自定义按钮和其他视图的画布;BMXSwipableCell
尽可能地模仿 iOS7 邮件应用的原始行为。
BMXSwipableCell
对故事板友好,因为它不自己实现单元格内容,而是使用 Interface Builder 中定义的元素。当然,也可以通过代码实现内容。
在 tableView:cellForRowAtIndexPath
中,BMXSwipableCell
在swiper时应显示什么内容时是通用的。它可以是两个按钮、一个按钮或完全不同的内容。因此,BMXSwipableCell
不自己实现“更多”和“删除”按钮,而是导出了一个“基础”视图,即接口构建器中定义的原生内容视图之下的视图。
将 BMXSwipableCellDemo/BMXSwipableCell
文件夹拖放到您的项目,并将其添加到您的目标中。
Custom Class
设为 BMXSwipableCell
。如果您根据代码操作,请使用 UITableView
注册 BMXSwipableCell
。tableView:cellForRowAtIndexPath
方法,并按需配置单元格。这里通过类别完成- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BMXSwipableCell *cell = (BMXSwipableCell *)
[tableView dequeueReusableCellWithIdentifier: @"Cell"
forIndexPath: indexPath];
[cell configureCellForItem: [_data objectAtIndex: indexPath.row]];
return cell;
}
在将子视图添加到基础视图之前,您可以通过属性 basementConfigured
检查单元格是否已初始化(可以重复使用单元格可以已经有自定义的基础内容)
@implementation BMXSwipableCell (ConfigureCell)
- (void)configureCellForItem:(BMXDataItem*)item
{
CGFloat cellHeight = CGRectGetHeight(self.bounds);
CGFloat x = self.basementVisibleWidth - cellHeight * 2;
//
// configure cell only if not already done
//
if (!self.basementConfigured) {
// first button...
//
// delete button
//
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.backgroundColor =
[UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0f];
deleteButton.frame = CGRectMake(x + cellHeight, 0, cellHeight, cellHeight);
[deleteButton setTitle:@"Delete" forState:UIControlStateNormal];
[deleteButton setTitleColor:[UIColor whiteColor]
forState: UIControlStateNormal];
[deleteButton addTarget: self
action: @selector(userPressedDeleteButton:)
forControlEvents: UIControlEventTouchUpInside];
[self.basementView addSubview: deleteButton];
}
// configure cell contents
}
//... more
UITableViewController
/ UITableViewDelegate
添加一些方法来管理设备旋转或列表滚动时的自动隐藏基础视图- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation: toInterfaceOrientation
duration: duration];
[BMXSwipableCell coverBasementOfAllCells];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[BMXSwipableCell coverBasementOfAllCells];
}
此代码也可以在 UITableViewController+BMXSwipableCellSupport
类别中找到,以方便您使用。
查看示例项目以获得完整使用示例。
自定义类
设置为 BMXSwipableCell
。背景
属性。