AFMSlidingCell 1.0.0

AFMSlidingCell 1.0.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年3月

Artjoms Haleckis 维护。




AFMSlidingCell 是用于在单元格下方显示任何类型按钮的 UITableViewCell 子类,可以通过滑动显示。这是一种常见的显示与单元格相关的动作(例如删除)的方式,而不会过载默认 UI。

Animated Example

AFMSlidingCell 支持最多添加到单元格右侧的两个不同尺寸的 UIButtons,并且可以直接从 Interface Builder 使用,也可以作为自定义单元格的基类。

用法

AFMSlidingCell 可以直接从 Interface Builder 使用 - 只需在身份检查器选项卡中将 UITableViewCell 的类设置为 AFMSlidingCell

最常用的方法是创建自定义 UITableViewCell。简单地从 AFMSlidingCell 继承而不是 UITableViewCell,您就准备好了!

在取出您的单元格后,您可以添加 UIButton

AFMSlidingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AFMSlidingCell" forIndexPath:indexPath];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundColor:[UIColor greenColor]];
[cell addFirstButton:button withWidth:42.0 withTappedBlock:^(AFMSlidingCell *cell) {
  NSLog(@"Cell tapped");
}];

您可以添加任何类型、配置其状态、图像等 UIButton。总共可以添加两个按钮

[cell addFirstButton:firstButton withWidth:23.0 withTappedBlock:^(AFMSlidingCell *cell) {
  NSLog(@"First button tapped");
}];
[cell addSecondButton:button withWidth:42.0 withTappedBlock:^(AFMSlidingCell *cell) {
  NSLog(@"Second tapped");
}];

如果您只想添加一个 UIButton,您将其添加为第一个或第二个按钮没有区别。

您可以对单元格有额外的控制,例如,可以程序性地显示或隐藏添加的按钮

[cell showButtonViewAnimated:YES];
[cell hideButtonViewAnimated:NO];

可以通过 AFMSlidingCellDelegate 获取按钮显示/隐藏的回调,以及禁止某些单元格显示按钮

- (BOOL)shouldAllowShowingButtonsForCell:(AFMSlidingCell *)cell
{
  if (cell == self.forbiddenCell)
    return NO;
  return YES;
}

要求

iOS 7 及以上。

安装

AFMSlidingCell 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中

pod 'AFMSlidingCell'

联系方式

Artjoms Haleckis, [email protected]

许可证

AFMSlidingCell 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。