OGeek|极客世界-中国程序员成长平台

标题: ios - 设置 UIContextualAction 大小 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:43
标题: ios - 设置 UIContextualAction 大小

我想知道是否可以设置 UIContextualAction 大小(宽度和高度)。

我在 UIContextualAction 中没有找到任何允许我这样做的成员,所以我想知道是否有一个解决方法可以做到这一点?

action.image = UIGraphicsImageRenderer(size:CGSize(width: 35, height: 35  )).image { _ in
    UIImage(named:"Delete")?.draw(in: CGRect(x:  0, y: 0, width: 35, height: 35))
}

action.backgroundColor = UIColor.red
return action

result

更新

我找到了这篇文章,背后的想法是使用自定义按钮并使用 UIGesture

https://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views



Best Answer-推荐答案


您可以使用此语法为 UIContextualAction 设置宽度和高度:

let contextAction = UIContextualAction(style: .normal, title: "", handler: { 
        (param: (Bool) -> Void) in param(true)
})  

contextAction.image = UIGraphicsImageRenderer(size: CGSize(160, 90)).image { 
    _ in UIImage(named: "someObject")!.draw(in: CGRect(40, 10, 200, 100))
}

contextAction.backgroundColor = .green

关于ios - 设置 UIContextualAction 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48672723/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4