How to add a hover effect to a UITableViewCell (Swift)

When iPadOS 13.4 was released so was much improved Mouse-Pointer support. While a non starter on your iPhone, iPad with a trackpad and external keyboard quickly turns into a very capable computing device.

For my app – Open Access Helper – I wanted to support this feature, even if it wouldn’t be used a lot. For most UI Elements, such as Buttons it can be as easy as adding something like the following to your ViewDidLoad method:

VoilĂ  – those buttons suddenly support the Mouse Pointer interaction. What proved harder was to actually provide a hover effect on TableViews.

It probably just boils down to me not understanding the documentation and possible not “googling” the problem quite right, but I eventually figured out how to do it.

The trick is that you need to apply the effect to your UITableViewCell. In your awakeFromNib() you configure the interaction, i.e. by calling an appropriate method for those devices in iOS 13.4 or higher.

Below a super basic “GenericTableViewCell” Class, that does nothing but show the implementation.

How to add a hover effect to a UITableViewCell (Swift)
Scroll to top