Search code examples
iosswiftuicontextualaction

UIContextualAction icon and text alignment


While testing our app we came across an interesting bug. We have some swipe actions in our table configured like so:

let retryAction = UIContextualAction(style: .destructive, title: "Remove")
retryAction.image = UIImage(named: "iconUploadRemove")

let retryAction = UIContextualAction(style: .normal, title: "Retry")
retryAction.image = UIImage(named: "iconUploadRetry")

Since we set an image, users would normally see icons when they swipe on the table row:Swipe Action with Icons

Swipe Action with Icons

But if a user increases their text sizeIncreases their text size

Then the action titles show up along with the icons

the action titles show up along with the icons

Having both text and icon isn't necessarily a problem except for the alignment/spacing of the text between the two actions. It appears to be the length of the string that is causing this. If I set the text to the same string, both actions are aligned equally. I know I can set the title to nil, which would prevent the text from appearing when large text is enabled.

But why does the text show up in this mode? And is it possible to have both the text and the icon display correctly aligned on each action button?


Solution

  • It doesn't appear there is an answer to why the text appears, and appears mis-aligned.

    For anyone who comes across this question, we ended up setting the titles to nil for these buttons to keep them "icon only".