0

I am implementing a UITableView with a checkmark on the left of the label and a custom accessoryView with a button on the right side. The checkmarks are selected and deselected in didSelectRowAt(indexPath). The custom button for the accessoryView is implemented as follows:

let button = UIButton(type: .custom)
button.setImage(UIImage(named: "arrow-right-light.png")?.maskWithColor(color: .white), for: .normal)
button.sizeToFit()
button.addTarget(self, action: #selector(buttonTest), for: .touchUpInside)
button.tag = indexPath.row
cell.accessoryView = button

However, there is a small area on the corner right of the table view (indicated in image below) that still responds to didSelectRowAt(indexPath).

Area between button and tableView edge that still responds to didSelectRowAt(indexPath)

Does anyone have any suggestions on how I can have the button snap to the rightMargin of the tablewView programmatically? I want the user to be able to hit the area from the button till the edge of the table without selecting the checkmark (indicated in image below):

expected button selection area

Thank you.

christopher.online
  • 2,614
  • 3
  • 28
  • 52
Richa Netto
  • 305
  • 2
  • 4
  • 8
  • I might suggest creating a custom `UITableViewCell` subclass at this point. You’ve done a great job customizing the default cell style but the layout isn’t really modifiable. You can obtain the exact positioning desired with a custom cell, without making that button the accessory view. – Jordan H Apr 21 '18 at 04:27
  • Thanks @Joey, I was able to add edge insets to the button view and obtain the results I wanted :) – Richa Netto Apr 22 '18 at 08:54

0 Answers0