development

UIFont-시스템 얇은 글꼴을 얻는 방법

big-blog 2020. 8. 27. 08:13
반응형

UIFont-시스템 얇은 글꼴을 얻는 방법


UIFont일반 글꼴 ( systemFontOfSize) 또는 굵은 글꼴 ( boldSystemFontOfSize)을 얻는 방법이 있지만 스토리 보드를 통해 사용할 수있는 "얇은 시스템 글꼴"을 얻는 방법은 무엇입니까?

UIFontContructor에 "system-thin"을 전달하는 것은 작동하지 않으며,이 생성자는 시스템 글꼴이 아닌 경우에만 작동합니다.


시스템 글꼴 얇은 두께를 사용할 수 있습니다.

UIFont.systemFont(ofSize: 34, weight: UIFontWeightThin)

샌프란시스코에 사용할 수있는 가중치 목록 :

UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
UIFontWeightBlack

샌프란시스코 글꼴 가중치

iOS 11 UIFontWeight* 부터는 UIFont.Weight.*. 자세한 내용은 https://developer.apple.com/documentation/uikit/uifont.weight에서 얻을 수 있습니다 .


iOS 8.2 부터는 다음을 사용할 수 있습니다UIFont.systemFontOfSize(_ fontSize: CGFloat, weight weight: CGFloat).

UIFont.systemFontOfSize(19, weight: UIFontWeightLight)

iOS SDK는 가중치에 대한 상수를 제공했습니다.

UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy

Using system font is better than creating a font based on font name when you want to use system fonts since iOS can change their system fonts on iOS (like when they did with Helvetica Neue in iOS 7, and now, San Francisco in iOS 9).

So what I would suggest is to include TTF file of the font you want as use that ttf file as custom font and use the custom font in your app.

This is the special reason why I don't like Apple. Never go what Apple say. Always do what we want. Apple keep on changing Default font for every OS.


Also if you want to keep same font size and just change weight then use from targeted element font size. For example:

demoLabel.font = UIFont.systemFont(ofSize: demoLabel.font.pointSize, weight: UIFontWeightThin)

with this you can keep default label font size and just change weight.

iOS 11부터 UIFontWeightThin의 이름이 UIFont.Weight.thin. 자세한 내용은 https://developer.apple.com/documentation/uikit/uifont.weight에서 얻을 수 있습니다 .


스위프트 4.2

 label.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.thin)

참고 URL : https://stackoverflow.com/questions/31771679/uifont-how-to-get-system-thin-font

반응형