SwiftUI 自定义字体加载缓慢

问题描述 投票:0回答:0

我在使用SwiftUI构建app的时候,在项目中使用了自定义字体来显示emojis(字体ttf文件有23.7M)。使用自定义字体时,代码如下:

ContentView 会加载缓慢。

struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach(0..<100, id: \.self) { i in
                    Text(verbatim: "\u{1fa84}")
                        .font(.custom("NotoColorEmoji", size: 18))
                        .foregroundColor(.secondary)
                }                    }
            .frame(height: 400)
        }
    }
}

应用程序启动并显示页面大约需要3秒。

如果注释掉

.font(.custom("NotoColorEmoji", size: 18))
,一切都会好的

那么如何提高性能或者预加载ttf字体文件呢?

我在这里写了一个demo,请问有什么好的方法可以解决这个问题吗

swiftui fonts core-text custom-font
© www.soinside.com 2019 - 2024. All rights reserved.