【问题标题】:Font Size Changes in iOS unexpectedlyiOS中的字体大小意外更改
【发布时间】:2021-04-22 22:32:14
【问题描述】:

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

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

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

下面的视图是在一个非常通用的 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@*/)
    }

【问题讨论】:

    标签: ios fonts display


    【解决方案1】:

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

    您是否可以在其他地方设置 default 字体?

    我可以通过这样做重现你得到的结果(使用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)
            }
        }
    }
    

    【讨论】:

    • 谢谢你,确实 - 将 .font(.body) 放在调用它的选项卡视图中解决了它。我非常感谢您的指导。我学到了一些东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2014-03-17
    • 2021-12-25
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    相关资源
    最近更新 更多