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 키로 사용합니다. 이 유형에는 잘 알려진 축 이름 세트가 있습니다. IE .weight ( wght ), .width ( wdth ) 등.이 유형은 ExpressibleByStringLiteral 입니다. 문자열 리터럴은 사용자 정의 축 이름에 사용할 수 있습니다.