繁体   English   中英

iOS 中的字体大小意外更改

[英]Font Size Changes in iOS unexpectedly

我是 iOS 和 SwiftUI(2 个月)的新手。 我正在努力理解以下行为,并希望有人能指出我如何诊断。

我有这段代码在预览提供程序中成功生成了这个视图

在此处输入图像描述

但是,当我在设备或模拟器中运行它时,fonts 会发生变化(系统映像也会发生)看起来更像这样(放大)。

在此处输入图像描述

下面的视图是在一个非常通用的 tabview 中呈现的——我根本无法理解它,可以使用一些指导。

谢谢

克雷格

    var body: some View {

        VStack(spacing: 0.0) {
            HStack(alignment: .top){
                Text(player.firstName)
                    .bold()
                Text(player.lastName)
                    .bold()
            }
            .font(.title)
            HStack {
                Image(uiImage: UIImage(data: player.playerPhoto) ?? UIImage())
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 100)
                    .clipShape(Circle())
                    .overlay(Circle().stroke(Color.purple, lineWidth: 4.0))
                Spacer()
                VStack {
                    Text("lifetime averages")
                        .font(.body)
                        .foregroundColor(Color.gray)
                    HStack {
                        Spacer()
                        VStack {
                            Text("Batting")
                                .font(.title2)
                                .bold()
                            Text("\(battingAverage, specifier: "%.3f")")
                        }
                        .padding(.leading)
                        if isPitcher {
                            Spacer()
                            VStack {
                                Text("ERA")
                                    .font(.title2)
                                    .bold()
                                Text("\(earnedRunAverage, specifier: "%.2f")")
                            }
                            .padding(.trailing)
                            Spacer()
                        }
                    }
                }
                Spacer()
            }
            HStack {
                VStack {
                    Text("\(noTeams)")
                        .font(.headline)
                    Text("teams")
                        .font(.subheadline)
                        .foregroundColor(Color.gray)
                }
                .padding(.leading, 10)
                Spacer()
                VStack {
                    Text("\(noSeasons)")
                        .font(.headline)
                    Text("seasons")
                        .font(.subheadline)
                        .foregroundColor(Color.gray)
                }
                Spacer()
                VStack {
                    Text("\(noGames)")
                        .font(.headline)
                    Text("games")
                        .font(.subheadline)
                        .foregroundColor(Color.gray)
                }.padding(.trailing, 10)

            }
            HStack{
                Spacer()
                Text("All Lifetime Stats >")
                    .font(.callout)
                    .foregroundColor(Color.blue)
            }
        }
        .frame(width: 350, height: 200, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
    }

您的代码没有为这两个Text元素指定.font(...)

您是否有可能在其他地方设置了默认字体?

我可以通过这样做来重现你得到的东西(使用PlayerView作为独立视图,而不是在表格中)。

如果使用UIKit App Delegate ,在willConnectTo session

    let contentView = PlayerView()
        .font(.largeTitle)

或者,如果使用SwiftUI App

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            PlayerView()
                .font(.largeTitle)
        }
    }
}

暂无
暂无

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

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