Post

Replies

Boosts

Views

Activity

Custom fonts stop showing sometimes when you switch applications in SwiftUI
I have loaded custom fonts into my SwiftUI project in Xcode to a folder, with the target membership set to the correct build, I have included the correct names inside the info.plist in the fonts provided by application section, and included them in the code using the correct names as such: extension Font { static let mainFont: (FontWeights, CGFloat) -> Font = { fontType, size in switch fontType { case .hairline: Font.custom("TT Norms Pro Thin", size: size) case .thin: Font.custom("TT Norms Pro ExtraLight", size: size) case .light: Font.custom("TT Norms Pro Light", size: size) case .regular: Font.custom("TT Norms Pro Regular", size: size) case .medium: Font.custom("TT Norms Pro Medium", size: size) case .semiBold: Font.custom("TT Norms Pro DemiBold", size: size) case .bold: Font.custom("TT Norms Pro Bold", size: size) case .heavy: Font.custom("TT Norms Pro ExtraBold", size: size) case .black: Font.custom("TT Norms Pro Black", size: size) } } static let serifFont: (SerifFontWeights, CGFloat) -> Font = { fontType, size in switch fontType { case .semiBold: Font.custom("Butler Free Bd", size: size) } } } extension View { func mainFont(_ fontWeight: FontWeights? = .regular, _ size: CGFloat? = nil) -> some View { return font(.mainFont(fontWeight ?? .regular, size ?? 16)) } func serifFont(_ fontWeight: SerifFontWeights? = .semiBold, _ size: CGFloat? = nil) -> some View { return font(.serifFont(fontWeight ?? .semiBold, size ?? 16)) } } Most of the time this works and the font shows, but if I switch applications, often some of the fonts disappear and the standard iOS font shows. Sometimes, but rarely, it also already doesn't show correctly on launch. I also tried simpler ways to include the font and different font files, but it causes the same behavior. What could be the reason for this erratic behavior?
1
0
447
Aug ’24
Set .toolbarColorScheme to white with a transparent background in SwiftUI
In SwiftUI I need to make the statusbar content (time, battery) white without any background color, only the image I specified for the view is behind it. The ideal way would be to use .toolbarColorScheme and do this: .toolbarColorScheme(.dark, for: .navigationBar) .toolbarBackground(Color.white.opacity(0), for: .navigationBar) .toolbarBackground(.hidden, for: .navigationBar) However, .toolbarColorScheme with a .dark value always automatically has a dark colored material background and can't be used without it. Is there any way to still use it and remove the dark background? (for instance with introspect) After trying many different other ways, none of them worked without breaking something else. I also can't use .preferredColorScheme because then I can't make the smooth transitions work between the main view where the statusbar content needs to be dark and the detail view where the statusbar content needs to be white.
0
1
364
Jan ’23