我做了一个自定义的UITableViewRowAction.现在我想添加一个图像而不是文本.我知道这是可能的,但不知道该怎么做.你们中的某些人是否知道如何在Swift中做到这一点并想帮助我?谢谢你的回答!
我在"editActionsForRowAtIndexPath"方法中使用了UITableViewRowAction.我可以更改UITableViewRowAction的backgroundcolor,但无法更改标题颜色.但我想改变UITableViewRowAction的颜色.关于这方面的任何意见都是值得注意的.
从右侧滑动单元格时如何添加自定义图像以删除按钮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"
这种方法的最佳方法是什么?
示例代码可能很明显.
我有经典的TableView,如果你滑动而不是单击按钮,你可以删除项目.我知道如何在单元格上设置自定义背景,但我找不到如何设置自定义字体和颜色.
谢谢你的帮助!
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
var deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,
title: "Delete",
handler: {
(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
println("Delete button clicked!")
})
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]
}
Run Code Online (Sandbox Code Playgroud) 我实现editActionsForRowAtIndexPath
和commitEditingStyle
轻扫是工作,但没有编辑动作出现在UITableViewCell
我的实施editActionsForRowAtIndexPath
和commitEditingStyle
如下:
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
//I did some work here
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
//I did some work here
tableView.reloadData()
})
return [deleteAction]
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激
有没有办法以编程方式触发相当于在具有编辑操作的UITableViewCell上向左滑动?这与简单的[tableView setEditing:YES animated:YES]
方法不同,因为该方法将整个表设置为编辑模式并显示插入/删除左附件视图和/或重新排序控件而不是单行的编辑操作.
我cell
想像邮件应用程序一样进行滑动操作.
我设置UIImage
了backgroundColor
行动作.
action.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"remove"]];
Run Code Online (Sandbox Code Playgroud)
但我在背景上并排重复我的图像.像这样. 在此输入图像描述
图像尺寸有问题吗?可以告诉我如何解决它,或另一种方法来做到这一点?
有几个类似的问题,但我认为应该有使用Swift3的iOS 10的最新答案,它不使用私有API,并且不依赖于您将图标限制为unicode表情符号.
我现在有三个动作的表行:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let rename = UITableViewRowAction(style: .normal, title: "Rename") { (_, indexPath) in
self.renameEntry(indexPath)
}
let locate = UITableViewRowAction(style: .normal, title: "Locate") { (_, indexPath) in
self.locateEntry(indexPath)
}
locate.backgroundEffect = UIVisualEffect()
let delete = UITableViewRowAction(style: .default, title: "Forget") { (_, indexPath) in
self.deleteEntry(indexPath)
}
return [delete, locate, rename]
}
Run Code Online (Sandbox Code Playgroud)
但是,我想要的不是我所选择的大小和样式的居中文字的颜色方块,而是:
我尝试使用backgroundColor,但只是将图像平铺在按钮上,并没有改变文本的位置或颜色.所以它必须不仅仅是
theAction.backgroundColor = UIColor(patternImage: UIImage(named: "renameImage")!)
Run Code Online (Sandbox Code Playgroud)
有这样做的好方法吗?
我有以下swift代码来实现UITableViewRowAction,当我滑动一行时,行按预期向左滑动,但是所有Section Header Rows也同时向下滑动到表行.
我还包括一个屏幕截图来显示正在发生的事情
如果我删除viewForHeader覆盖并用titleForHeaderInSection替换它,那么我没有问题.
覆盖viewForHeader的原因是我想在Header Row中放置一个图像.
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCellWithIdentifier("header") as UITableViewCell
cell.textLabel?.text = instrumentGroups[section].name
cell.imageView?.image = UIImage(named: instrumentGroups[section].name)
return cell
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> InstrumentTableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("instrumentCell", forIndexPath: indexPath) as InstrumentTableViewCell
cell.instrument = instrumentGroups[indexPath.section].instruments[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let instrument = instrumentGroups[indexPath.section].instruments[indexPath.row]
var actions: [AnyObject] = []
var action = UITableViewRowAction(style: …
Run Code Online (Sandbox Code Playgroud) 我有一个侧面滑动菜单实现了UITableView
使用UITableViewRowAction
.我想在此菜单中添加"完成"按钮,并在用户编辑单元格时将其显示.按下"完成"后,操作将正常完成.
我可以以编程方式呈现UITableViewRowAction
特定的表视图行吗?
要么
UITableViewRowAction
用户点击其中一个按钮后,我可以保持可见吗?
user-interface objective-c uitableview ios uitableviewrowaction