[英]Font Size Changes in iOS unexpectedly
All I'm new to iOS and SwiftUI (2 months).我是 iOS 和 SwiftUI(2 个月)的新手。 I'm struggling to understand the following behavior and hope someone can point me as to how I can diagnose.我正在努力理解以下行为,并希望有人能指出我如何诊断。
I have this code successfully generating this view in the preview provider我有这段代码在预览提供程序中成功生成了这个视图
however when I run it on a device or in the simulator the fonts change (happens for system images also) to look more like this (scaled up).但是,当我在设备或模拟器中运行它时,fonts 会发生变化(系统映像也会发生)看起来更像这样(放大)。
The view below is rendered inside of a very generic tabview - I cant fathom it at all and could use some guidance.下面的视图是在一个非常通用的 tabview 中呈现的——我根本无法理解它,可以使用一些指导。
Thanks谢谢
Craig克雷格
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@*/)
}
Your code does not specify a .font(...)
for those two Text
elements.您的代码没有为这两个Text
元素指定.font(...)
。
Is it possible you have set the default font somewhere else?您是否有可能在其他地方设置了默认字体?
I can reproduce what you're getting by doing this (using PlayerView
as a stand-alone view, not in a table).我可以通过这样做来重现你得到的东西(使用PlayerView
作为独立视图,而不是在表格中)。
If using UIKit App Delegate
, in willConnectTo session
:如果使用UIKit App Delegate
,在willConnectTo session
:
let contentView = PlayerView()
.font(.largeTitle)
or, if using SwiftUI App
:或者,如果使用SwiftUI App
:
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
PlayerView()
.font(.largeTitle)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.