Select view on tap

In the Reminders app, when you hold down on the alarm date, the field looks selected (it darkens). How would I duplicate that behavior in my app? Would I need to use a UIView for that field?

Hi @brower! If you are talking about what I think you are then what you are seeing is the selection state of a cell within a table view.

This is behaviour that comes as standard in UITableViewCell’s if you have it’s selectionStyle set to .default. Hope that helps!

Is there a way to do that without a table view? I’m not able to use a table view in what I’m trying to do. Thanks for the reply nonetheless.

Sure, you can use a UIButton and set a background image for a specific state (.highlighted)

https://developer.apple.com/documentation/uikit/uibutton/1624016-setbackgroundimage

The UILabel has an isHighlighted property. I tried setting it to true when the user taps on it, but I see no visible changes.

I think I got it to work as I want it to. I set the backgroundColor property to a different color when the user taps on the control. That’s probably good enough for me.

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.