我想编辑表格的 UITableViewRowAction
。我的单元格有圆边和边框,我想编辑 RowAction
的样式以匹配我的单元格的样式。
据我所知,目前只有 backgroundColor
、标题和样式(默认、破坏性、正常...)可以更改 ( link )。但是,我觉得这有点太受限制了?也许我可以子类化 UITableViewRowAction
来创建我自己的外观?任何建议将不胜感激。
很遗憾,我无法发布示例图片,因为我还没有 10 个代表(哈哈)。不过,我认为这个问题很简单,无需视觉表示也能理解。
最佳答案
正如您所说,您唯一可以更改的操作是:
- 背景颜色
- 风格(破坏性的(红色背景颜色,...)
- 标题
为了更改 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/