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

iOS에서 시스템 글꼴을 변경할 수 있기 때문에 시스템 글꼴을 사용하려는 경우 시스템 글꼴을 사용하여 글꼴 이름을 기반으로 글꼴을 만드는 것보다 낫습니다 (예 : iOS 7에서 Helvetica Neue, iOS 9에서 샌프란시스코). .

그래서 내가 제안하는 것은 ttf 파일을 사용자 정의 글꼴로 사용하고 앱에서 사용자 정의 글꼴을 사용하는 것처럼 원하는 글꼴의 TTF 파일을 포함하는 것입니다.

이것이 제가 애플을 좋아하지 않는 특별한 이유입니다. 애플이 말하는대로 하지 마십시오 . 항상 우리가 원하는 것을하십시오. Apple 은 모든 OS의 기본 글꼴을 계속 변경 합니다.


답변

또한 동일한 글꼴 크기를 유지하고 두께 만 변경하려면 대상 요소 글꼴 크기에서 사용하십시오. 예를 들면 :

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

이를 통해 기본 레이블 글꼴 크기를 유지하고 무게 만 변경할 수 있습니다.

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)


답변