
UIDrawTextFontDescriptor의 getWeight 메서드는 텍스트의 두께를 나타내는 Weight 값을 반환합니다. Weight는 텍스트의 두께를 측정하는 단위로, UIKit에서 정의한 8가지의 두께를 나타내는 값입니다.
Weight의 가능한 값은 다음과 같습니다:
- .thin
- .ultraLight
- .light
- .regular
- .medium
- .semibold
- .bold
- .heavy
이 메서드는 텍스트 렌더링 시에 텍스트의 두께를 조절할 때 사용됩니다. 예를 들어, 텍스트의 두께를 강조하고 싶을 때는 bold 값을 사용할 수 있습니다.
예시 소스코드:
#hostingforum.kr
swift
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .headline)
let weight = fontDescriptor.fontAttributes[.weight] as? String
print(weight) // regular
let boldFontDescriptor = fontDescriptor.withSymbolicTraits(.traitBold)
let boldWeight = boldFontDescriptor.fontAttributes[.weight] as? String
print(boldWeight) // bold
이 예시 소스코드에서는 UIFontDescriptor를 사용하여 텍스트의 두께를 조절하는 방법을 보여줍니다. UIFontDescriptor의 withSymbolicTraits 메서드를 사용하여 텍스트의 두께를 강조할 수 있습니다.
2025-06-13 12:43