skip to Main Content

Tried to align text to leading of a view in swift ui within the navigation link its not working
but if I didn’t used navigation link its working fine

import SwiftUI

struct Test: View {
    
    var body: some View {
        NavigationView {
            NavigationLink {
                Text("fsdf")
            } label: {
                
                VStack(alignment: .leading) {
                    Text("sdfsdlfjskfjsd sdflkjsdf sf sljdflsdkf asfjslkdfj sdfjlskfj sdfjldksfj asdfvfvf fvfvf fvfvl,v vfvl")

                        .frame(maxWidth: .infinity,alignment:.leading)
                }
                .frame(width: 300,height: 100)
                .background(Color.yellow)
                .overlay {
                    
                }
                
            }
            
            
        }
    }
}

enter image description here
above is the output now

I need to output as below
enter image description here

my ultimate goal is while clicking on the entire view I need to navigate to next view ,

2

Answers


  1. Use Text modifier .multilineTextAlignment(.leading)

    struct Test: View {
        
        var body: some View {
            NavigationView {
                NavigationLink {
                    
                } label: {
                    
                        // Your code
                    
                        Text("sdfsdlfjskfjsd sdflkjsdf sf sljdflsdkf asfjslkdfj sdfjlskfj sdfjldksfj asdfvfvf fvfvf fvfvl,v vfvl")
                            .multilineTextAlignment(.leading)
                    
                        //
                }
            }
        }
    }
    
    Login or Signup to reply.
  2. this might be useful to you..

    var body: some View {
        NavigationView {
            NavigationLink {
                Text("fsdf")
            } label: {
                VStack(alignment: .leading) {
                    Text("sdfsdlfjskfjsd sdflkjsdf sf sljdflsdkf asfjslkdfj sdfjlskfj sdfjldksfj asdfvfvf fvfvf fvfvl,v vfvl")
                        .frame(maxWidth: .infinity, alignment: .leading)
                        .padding(.leading) 
                }
                .frame(width: 300, height: 100)
                .background(Color.yellow)
            }
        }
    }
    

    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search