【发布时间】:2018-02-01 02:10:23
【问题描述】:
这是我在使用 UITableView 时遇到的一些问题,更准确地说是在 tableView 中使用图像:editActionsForRowAt:
下面是我的相关代码。说我在这里使用的图像都是 70x70 的正方形可能会很有用。
func tableView(_ tableView: UITableView,
editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
var patternImg:UIImage?
let upBtn = UITableViewRowAction(style: .normal, title: "") {
action, index in
print("upBtn button tapped")
}
patternImg = self.swipeCellImage(named: "UpIcn", side: 46.0)
upBtn.backgroundColor = UIColor(patternImage: patternImg!)
let downBtn = UITableViewRowAction(style: .normal, title: "") {
action, index in
print("downBtn button tapped")
}
patternImg = swipeCellImage(named: "DownIcn", side: 46.0)
downBtn.backgroundColor = UIColor(patternImage: patternImg!)
let rmvBtn = UITableViewRowAction(style: .destructive, title: "") {
action, index in
print("rmvBtn button tapped")
}
patternImg = swipeCellImage(named: "TrashIcn", side: 46.0)
rmvBtn.backgroundColor = UIColor(patternImage: patternImg!)
return [downBtn,upBtn,rmvBtn]
}
func swipeCellImage(named name: String, side: CGFloat) -> UIImage? {
let theImage = UIImage(named: name)
UIGraphicsBeginImageContextWithOptions(CGSize(width: side*2, height: side), false, UIScreen.main.scale)
let context = UIGraphicsGetCurrentContext()
context!.setFillColor(UIColor.clear.cgColor)
theImage?.draw(in: CGRect(x: 0, y: 0, width: side, height: side))
let resultImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return resultImage
}
一切正常,但不幸的是只达到了一定程度。 查看此屏幕截图显示图像存在不必要的重复。显然我希望每个按钮(图标)每次只出现一次。
谁能看到我需要如何修复我的代码以避免这种重复?
【问题讨论】:
-
您在哪个操作系统中运行?? iOS 11 或更低版本?
-
我使用的是 iOS 11.2.2。
-
好的。会检查并更新你
-
我的ans更新了。
标签: ios swift uitableview uitableviewrowaction