繁体   English   中英

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM