In SwiftUI, are there any good ways to set a custom tap target, to ensure it's always 44x44.

for example: Our designers want our "Disclosures/Legal" info icon, to be 4px from the text. So we end up needing to "hack" around the view, to make the info tap target exist "over" the text.

  • without any hacks, if we use a 20x20 icon + 4 padding, the tap target is only 28px wide.
  • the "hack" in question, usually involves adding paddings + inverted (negative) padding, to increase the tap target, without affecting layout
Answered by Engineer in 891242022

You should be able to use content shape to increase the tap area:

.contentShape(
    Circle().inset(by: -8)
)

You should be able to use content shape to increase the tap area:

.contentShape(
    Circle().inset(by: -8)
)
In SwiftUI, are there any good ways to set a custom tap target, to ensure it's always 44x44.
 
 
Q