我做了一个自定义的UITableViewRowAction.现在我想添加一个图像而不是文本.我知道这是可能的,但不知道该怎么做.你们中的某些人是否知道如何在Swift中做到这一点并想帮助我?谢谢你的回答!
我想在Swift中的tableviewCell中的滑动操作中放置图标(图像)而不是文本.
但我不知道如何把图像而不是标题文字?
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Share" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
// 2
let shareMenu = UIAlertController(title: nil, message: "Share using", preferredStyle: .ActionSheet)
let twitterAction = UIAlertAction(title: "Twitter", style: UIAlertActionStyle.Default, handler: nil)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
shareMenu.addAction(twitterAction)
shareMenu.addAction(cancelAction)
self.presentViewController(shareMenu, animated: true, completion: nil)
})
// 3
var rateAction = (style: UITableViewRowActionStyle.Default, title: "rate",im , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> …Run Code Online (Sandbox Code Playgroud) 从右侧滑动单元格时如何添加自定义图像以删除按钮UITableview,如下图所示?
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let remove = UITableViewRowAction(style: .Default, title: "\nRemove") { action, indexPath in }
remove.backgroundColor = UIColor(patternImage: UIImage(named: "remove")!) }
Run Code Online (Sandbox Code Playgroud)
从上面的代码中可以看到Image,但它显示为堆叠在一起的一组图像.我的意思是,我无法设置"ContentMode"到".ScaleToAspectFit"了"UIImage"
这种方法的最佳方法是什么?
示例代码可能很明显.
我刚刚在iOS8上遇到过这个新的API.但是,如果可以使用图像而不是文本并允许左右滑动,我无法找到任何解决方案?这甚至可能吗?我发现的唯一实现是:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
[self.tableView setEditing:NO];
}];
moreAction.backgroundColor = [UIColor blueColor];
UITableViewRowAction *moreAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];
moreAction2.backgroundColor = [UIColor blueColor];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
return @[deleteAction, moreAction, moreAction2];
}
Run Code Online (Sandbox Code Playgroud) 我cell想像邮件应用程序一样进行滑动操作.
我设置UIImage了backgroundColor行动作.
action.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"remove"]];
Run Code Online (Sandbox Code Playgroud)
但我在背景上并排重复我的图像.像这样. 在此输入图像描述
图像尺寸有问题吗?可以告诉我如何解决它,或另一种方法来做到这一点?