Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI multiline text in a NavigationView Title

How could I make this title multiline?

enter image description here

I have tried setting the title text as multiline or even configuring it with allowsThigtening(flag: Bool) but none of these options work.

Current code here:

import SwiftUI

struct DistributionCentersView: View {
    var dcViewModel = DistributionCenterViewModel()
    @State private var pickedSelectedData = 0
    @State private var searchTerm = ""

    init() {
        //...

    }

    var body: some View {
        NavigationView {
            VStack {
                VStack {
                    Picker(selection: $pickedSelectedData, label: Text("")){
                        Text("All").tag(0)
                        Text("Nevial").tag(1)
                        Text("Net power").tag(2)
                    }.pickerStyle(SegmentedPickerStyle())
                        .foregroundColor(Color.white)
                        .background(Color(#colorLiteral(red: 0.03921568627, green: 0.03921568627, blue: 0.03921568627, alpha: 1)))
                    SearchBar(text: $searchTerm)
                }
                .padding(.leading, 16)
                .padding(.trailing, 16)
                .padding(.top, 34)

                List {
                    ForEach (dcViewModel.distribuitionCenters){ dc in
                        ZStack { 
                            DistributionCenterCell()
                                .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
                            NavigationLink(destination: Text("Test")) {
                                EmptyView()
                            }.buttonStyle(PlainButtonStyle())
                        }// This optionm avoid tinting
                    }.listRowBackground(Color(#colorLiteral(red: 0.03921568627, green: 0.03921568627, blue: 0.03921568627, alpha: 1)))
                }
                .navigationBarTitle(Text(Constants.Distribution.text), displayMode: .large)//Desired multiline title
                .listStyle(GroupedListStyle())
                .navigationBarItems(leading: NavigationLink(destination: ProfileView()) { Image(Constants.NavImages.human).foregroundColor(Color.white)}, trailing: Image(Constants.NavImages.phone).foregroundColor(Color.white))
            }
            .background(Color(#colorLiteral(red: 0.03921568627, green: 0.03921568627, blue: 0.03921568627, alpha: 1)))
        }

    }
}
like image 331
Andoni Da Silva Avatar asked Jan 20 '20 15:01

Andoni Da Silva


1 Answers

For more information check this link

NavigationView {
    Text("Hello, SwiftUI!")
        .navigationBarTitleDisplayMode(.inline)
        .toolbar {
            ToolbarItem(placement: .principal) { 
                VStack {
                    Text("Title").font(.headline)
                    Text("Subtitle").font(.subheadline)
                }
            }
        }
}
like image 82
Zain Anjum Avatar answered Sep 20 '22 20:09

Zain Anjum