How to change the background color of a UIButton while it’s highlighted?

You can override UIButton‘s setHighlighted method. Objective-C – (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; if (highlighted) { self.backgroundColor = UIColorFromRGB(0x387038); } else { self.backgroundColor = UIColorFromRGB(0x5bb75b); } } Swift 3.0 and Swift 4.1 override open var isHighlighted: Bool { didSet { backgroundColor = isHighlighted ? UIColor.black : UIColor.white } }

Detecting which UIButton was pressed in a UITableView

In Apple’s Accessory sample the following method is used: [button addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; Then in touch handler touch coordinate retrieved and index path is calculated from that coordinate: – (void)checkButtonTapped:(id)sender { CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition]; if (indexPath != nil) { … } }