SwiftUI 中的文本视图不只显示更大的字体
Text view in SwiftUI doesn't show only with bigger font
在 DoctorHomePage 中我有一个分组列表,在列表上方我想添加一个文本视图,但是只有当我将字体更改为更大的字体时文本视图才不显示,但它太大了,我想要它更小。这是我的代码:
import SwiftUI
import Combine
struct DoctorHomePage: View {
@Binding var shouldPopToRootView : Bool
@State private var curent: Int? = nil
@State private var isActive: Bool = false
@State private var id = 0
let defaults = UserDefaults.standard
let networkRequest = Network()
@State var cancelable: AnyCancellable? = nil
@State var localPatients : [Patients] = []
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: ContentView(), tag: 1, selection: $curent) {
EmptyView()
}
Text("Welcome, doctor!") // this is the text that I want to add
.font(.system(size: 30)).fontWeight(.ultraLight)
.padding(.top, 50)
// PATIENT LIST
List(localPatients) { patient in
VStack(alignment: .leading) {
Text(patient.name)
}
}.listStyle(GroupedListStyle())
.onAppear(perform: {
self.loadPatients()
connCode = self.defaults.integer(forKey: "doctorID")
self.id = connCode
})
}.edgesIgnoringSafeArea([.top, .bottom])
}.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
}
}
这里有一些屏幕截图可以帮助您理解问题:
第一张图片没有文字视图。
第二张图片字体大小为60
第三张图片的字号是30
似乎有些奇怪的/错误的行为。
设置欢迎文本的 zIndex 将解决您的问题。
Text("Welcome, doctor!").zIndex(1)
在 DoctorHomePage 中我有一个分组列表,在列表上方我想添加一个文本视图,但是只有当我将字体更改为更大的字体时文本视图才不显示,但它太大了,我想要它更小。这是我的代码:
import SwiftUI
import Combine
struct DoctorHomePage: View {
@Binding var shouldPopToRootView : Bool
@State private var curent: Int? = nil
@State private var isActive: Bool = false
@State private var id = 0
let defaults = UserDefaults.standard
let networkRequest = Network()
@State var cancelable: AnyCancellable? = nil
@State var localPatients : [Patients] = []
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: ContentView(), tag: 1, selection: $curent) {
EmptyView()
}
Text("Welcome, doctor!") // this is the text that I want to add
.font(.system(size: 30)).fontWeight(.ultraLight)
.padding(.top, 50)
// PATIENT LIST
List(localPatients) { patient in
VStack(alignment: .leading) {
Text(patient.name)
}
}.listStyle(GroupedListStyle())
.onAppear(perform: {
self.loadPatients()
connCode = self.defaults.integer(forKey: "doctorID")
self.id = connCode
})
}.edgesIgnoringSafeArea([.top, .bottom])
}.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
}
}
这里有一些屏幕截图可以帮助您理解问题:
第一张图片没有文字视图。
第二张图片字体大小为60
第三张图片的字号是30
似乎有些奇怪的/错误的行为。
设置欢迎文本的 zIndex 将解决您的问题。
Text("Welcome, doctor!").zIndex(1)