4

I would like to know if it's possible to set the UIContextualAction size (width and height).

I didn't find any member in UIContextualAction that allow me to do that so I wonder if there is a walk-around to do this?

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

Update

I found this post, the idea behind is to use custom button and use UIGesture

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Wael
  • 411
  • 1
  • 6
  • 19
  • @matt in fact what made me think about it is : in my tableview i set spacing between rows using uiview with transparent color, when i swipe left the uicontextaction take the whole height of the row wish kind a ugly in this case – Wael Feb 07 '18 at 20:42
  • I misunderstood the q., sorry! If you use an image you can size it, I think – matt Feb 07 '18 at 20:46
  • U can size the image but it will not solve the pb cz the bakground will took the hole height – Wael Feb 07 '18 at 20:49
  • Were you able to find a solution? – KZoNE Feb 09 '23 at 17:21

1 Answers1

1

You might use this syntax to set width and height for 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
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • thank you , I tried this code but the pb if you set a color background like red it will not work – Wael Feb 07 '18 at 20:53
  • I update the post with screen shot and the code I use, as you can see the red background tool the hole row height. or I wanted only on the white area. – Wael Feb 07 '18 at 21:24