ios – Broaden / collapse Textual content with SwiftUI

[ad_1]

I’ve a SwiftUI view like this:

var physique: some View {
    
    VStack(alignment: .main) {
        
        Textual content(message)
            .font(.light16)
            .foregroundColor(.black)
            .multilineTextAlignment(.main)
            .padding(.backside, 8)

        ...

    }
}

This message typically may be very massive. I would really like that in that circumstances, when the Textual content element is larger than 200px (for instance), a develop/collapse button seems, so the consumer can learn a shorter model of the message (200px) or the complete message (its full top). One thing like this:

var physique: some View {

  VStack(alignment: .main) {

    Textual content(message)
        .font(.light16)
        .foregroundColor(.black)
        .multilineTextAlignment(.main)
        .padding(.backside, 8)

    Button {
                self.isCollapsed = !self.isCollapsed
                // develop or collapse the Textual content
            } label: {
                let title = self.isCollapsed ? "develop textual content" : "collapse textual content"
                Textual content(title)
                    .font(.bold14)
                    .foregroundColor(Shade.blue)
                    .multilineTextAlignment(.main)
                    .padding(.backside, 8)
            }

     }

     ...
 }

I’ve used GeometryReader and proxy in different events however I do not know how you can use it for this case. How may I get this performance?

[ad_2]

Leave a Reply