I am creating a disclosure group as follows:
DisclosureGroup(isExpanded: $isShowingAllOpeningHours) {
Text("Content")
.frame(maxWidth: .infinity, alignment: .leading)
.background(.red)
.padding(.bottom, .zero)
} label: {
Text("Title")
.background(.green)
.padding(.bottom, .zero)
}
.background(.yellow)
I’ve added the colors just to illustrate the point
This gives me the following the the disclosure group is collapsed
And this when it is expanded
There seems to be some padding around the label in a disclosure group as seen by the yellow background.
Is there a way to remove this padding.
Since this disclosure group is within a scrollview, I’ve tried adjusting insets but this did not work either.
2
Answers
The extra padding appears to be 4pt at top and bottom. This stays the same even when the text size is increased.
You can eliminate it by applying negative padding of the same amount:
Of course, the padding may change in a future iOS release. So you may want to restrict the workaround to versions for which you have tested it.
You can use your own
DisclosureGroupStyle
. Make it aVStack
with 0 spacing. You do need to reinvent the expansion logicAt the end of the
DisclosureGroup
, add