ios - UITableViewRowAction 自定义样式?

标签 ios objective-c uitableview

我想编辑表格的 UITableViewRowAction。我的单元格有圆边和边框,我想编辑 RowAction 的样式以匹配我的单元格的样式。

据我所知,目前只有 backgroundColor、标题和样式(默认、破坏性、正常...)可以更改 ( link )。但是,我觉得这有点太受限制了?也许我可以子类化 UITableViewRowAction 来创建我自己的外观?任何建议将不胜感激。

很遗憾,我无法发布示例图片,因为我还没有 10 个代表(哈哈)。不过,我认为这个问题很简单,无需视觉表示也能理解。

最佳答案

正如您所说,您唯一可以更改的操作是:

  1. 背景颜色
  2. 风格(破坏性的(红色背景颜色,...)
  3. 标题

为了更改 UITableViewRowAction 的样式,可能的解决方案是使用“patternimage”添加图像。

这是解决方案。我并不是说这是确切的解决方案,因为现在我们无法访问“UITableViewRowAction”的所有属性

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"test" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

    // show UIActionSheet
}];
float wwidth =[moreAction.title sizeWithAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:15.0]}].width;
wwidth = wwidth+<55 change this value for exact width>;
moreAction.backgroundColor = [[UIColor alloc] initWithPatternImage:[self imageWithImage:[UIImage imageNamed:@"temp.jpg"] scaledToSize:CGSizeMake(wwidth, tableView.rowHeight)]];

UITableViewRowAction *flagAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Flag" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
    // flag the row
}];
flagAction.backgroundColor = [UIColor yellowColor];

return @[moreAction, flagAction];
}

注意:使用高分辨率图像,以便它适用于

iPhone 6 Plus   736x414 points    5.5"
iPhone 6        667x375 points    4.7"
iPhone 5        568x320 points    4.0"
iPhone 4        480x320 points     3.5"

此链接上的有用帖子 http://pablin.org/

关于ios - UITableViewRowAction 自定义样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26907285/

相关文章:

ios - 将文本字段添加到 UITableview 单元格

ios - UITableView indexPath.row 问题

Titanium Studio 中未显示 iOS 模拟器

ios - 添加背景图像时在 NavigationBar 上显示深色阴影

iphone - CABasicAnimation 展开高度方向

ios - 从服务器下载数据并在 UITableViewController 或 UIViewController 中显示而不会卡住其 GUI 的最佳方法是什么?

ios - 获取所有带有附件类型复选标记的表格 View 单元格

ios - 当 tableView 向下滑动时显示 UISearchController

ios - 添加 WatchKit 目标后,它的文件变为红色

ios - 为什么我的 ViewController 在一次调用 present(_ :animated:completion:) method?