SwiftUI中的文本视图不会仅以更大的字体显示

时间:2020-03-27 14:17:33

标签: ios swift text textview swiftui

在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)
    }
}

以下屏幕截图可帮助您理解问题: enter image description here

第一张图片没有文本视图。

第二张图像的字体大小为60。

第三张图像的字体大小为30。

1 个答案:

答案 0 :(得分:2)

似乎有些奇怪/错误的行为。

设置欢迎文本的zIndex将解决您的问题。

20200321   text file 
TACL-SEC                          SECURITY      \SC1
TACL-SEC                          SECURITY      \SC2
TACL-SEC                          SECURITY      \SC2
TACL-SEC                          SECURITY      \SC2
TACL-SEC                          SECURITY      \SC2
TACL-SEC                          SECURITY      \SC2
20