swift variablefonts
1.1.0
ใช้แบบอักษรผันแปรได้ง่ายขึ้นกับ AppKit, Uikit และ Swiftui สำหรับ iOS, macOS, tvos, watchos และ visionos
ขยาย NSFont ของ AppKit, UIFont ของ UIFIT และ Font ของ Swiftui พร้อมคุณสมบัติแบบอักษรตัวแปร ไม่ง่ายกว่านี้!
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 ตัวอักษรสตริงสามารถใช้สำหรับชื่อแกนที่กำหนดเอง