I have created a struct to have my fonts pre cached available globally:
struct Fonts {
static let avenirRegular = UIFont(name: "AvenirNextCondensed-Regular", size: 14.0)
}
Usage...:
xy.font = Fonts.avenirRegular
It tells me, that my constant is an Optional.
Value of optional type 'UIFont?' not unwrapped; did you mean to use '!' or '?'?
Why is it an optional? Is there a chance that AvenirNextCondensed-Regular
is not available on every iOS devices? Help is very appreciated.
optional. Gives the font face an extremely small block period and no swap period.
The font size is a number that indicates how many points are in the height of the text, or high tall the text is in points. A point is 1/72 of an inch, so a 12-point font would be 12/72 of an inch.
You can! That's what font-display: optional; does. It still gives the ~100ms font block period (giving the font a fighting chance to show up on first page view), but after that, the fallback is shown and will not swap. Chances are, the font did ultimately get downloaded, and next page view it will be cached and used.
The font-display property defines how font files are loaded and displayed by the browser. It is applied to the @font-face rule which defines custom fonts in a stylesheet.
the "optional" here means that the problem is the font might not exist(even though we know it does) and you have to recognize it, by making it optional you are telling the compiler that I know the font is not part of your library BUT I am sure it is there.
The initializer you are using for UIFont
is return optional UIFont?
object ie the reason you are getting that suggestion for wrapping optional.
init?(name fontName: String, size fontSize: CGFloat)
Check Apple Documentation of UIFont
for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With