Home > OS >  SwiftUI Disclosure Group Text Alignment
SwiftUI Disclosure Group Text Alignment

Time:08-01

Is there a way to prevent wrapped text in a DisclouseGroup title from being center aligned?

Disclosure group with center aligned text

I have tried to add the following, but neither approach has been effective:

DisclosureGroup("A really long disclosure group title that is being center aligned.", isExpanded: false) {
   ...
}
.multilineTextAlignment(.leading)
DisclosureGroup("A really long disclosure group title that is being center aligned.", isExpanded: false) {
   ...
}
.frame(maxWidth: .infinity, alignment: .leading)

CodePudding user response:

You can use the Label initialiser for DisclosureGroup. You can read more about it enter image description here

Tested Xcode 14 beta 4 iOS 16 Simulator

CodePudding user response:

You can wrap it in a Form or a List:

struct DisclosureAligning: View {

    @State var isExpanded = false

    var body: some View {
        Form {
            DisclosureGroup("A really long disclosure group title that is being center aligned.", isExpanded: $isExpanded) {
                Text("text")
            }
        }
    }
}
  • Related