swift variablefonts
1.1.0
与AppKit,Uikit和Swiftui一起使用可变字体。用于iOS,macOS,TVOS,WatchOS和Visionos
扩展了具有可变字体功能的AppKit的NSFont ,Uikit的UIFont和Swiftui的Font 。再容易了!
let font = NSFont ( name : " Amstelvar " , size : 20 , axes : [
. weight : 650 ,
. opticalSize : 144 ,
" GRAD " : 500 ,
] ) let scienceGothic = UIFont ( name : " ScienceGothic " , size : 20 ) !
let slanted = scienceGothic . withAxis ( . slant , value : - 10 ) let tiltWarp = NSFont ( name : " TiltWarp-Regular " , size : 100 ) !
let axes = tiltWarp . allAxes ( )
print ( axes )
/*
[VariableFonts.FontAxis(
id: 1481789268,
name: "XROT",
description: "Rotation in X",
minimumValue: -45.0,
maximumValue: 45.0,
defaultValue: 0.0),
etc...]
*/ Text ( " Hello world " )
. font ( . custom ( name : " Fraunces " , size : 40 , axes : [
. weight : 900 ,
" SOFT " : 100 ,
" WONK " : 1 ,
] ) ) let nunito = UIFont ( name : " NunitoSans " , size : 20 ) !
let axes = nunito . allAxes ( )
// Creates a UIFont with all axes set to their maximum value.
let megaNunito = nunito . withAxes (
Dictionary ( uniqueKeysWithValues : axes . map { axis in
return ( axis . id , axis . maximumValue )
} )
) 您提供的字典配置轴使用FontAxis.Name作为键。这种类型带有一组知名的轴名称。 .weight wght .width wdth ExpressibleByStringLiteral字符串文字可用于自定义轴名称。