【发布时间】:2020-01-20 15:02:42
【问题描述】:
我怎样才能使这个标题多行?
我尝试将标题文本设置为多行,甚至使用allowThigtening(flag: Bool) 进行配置,但这些选项都不起作用。
这里的当前代码:
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)))
}
}
}
【问题讨论】:
-
为什么不改变标题的设计?
-
来自设计部门,标题必须有两行。
-
能否添加您的代码
-
据我所知,标准 UINavigationBar(目前在 NavigationView 中使用)不支持多行文本标题。因此,如果有这样的要求,您需要自定义标题栏并使用 NavigationView 进行导航,并隐藏默认导航栏。
标签: ios swift uinavigationcontroller swiftui navigationview