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

问题描述 投票:2回答: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)
    }
}

以下是一些屏幕快照,可帮助您理解问题:enter image description here

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

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

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

ios swift text textview swiftui
1个回答
2
投票

似乎是某些奇怪/越野车的行为。

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

Text("Welcome, doctor!").zIndex(1)
© www.soinside.com 2019 - 2024. All rights reserved.