
UIDrawTextFontDescriptor 클래스의 getWeight 메서드는 font의 굵기를 반환합니다. 이 메서드는 font descriptor를 생성할 때 사용됩니다.
getWeight 메서드는 UIFont.Weight enum의 값을 반환합니다. UIFont.Weight enum에는 8가지 종류의 굵기가 정의되어 있습니다.
이 값을 사용하는 시점에서 고려해야 하는 사항은 font descriptor를 생성할 때 font의 굵기를 정확하게 지정해야 한다는 점입니다.
getWeight 메서드는 font descriptor를 생성할 때 사용이 가능합니다. 하지만, font descriptor를 생성할 때 font의 이름, style, size, weight를 모두 지정해야 하므로, getWeight 메서드를 사용하기 전에 font descriptor를 생성하는 모든 요소를 고려해야 합니다.
예를 들어, 다음과 같이 font descriptor를 생성할 수 있습니다.
#hostingforum.kr
swift
let fontDescriptor = UIFontDescriptor.fontDescriptorWithFamily("Helvetica")
let fontDescriptor = fontDescriptor.addingAttributes([.weight: UIFont.Weight.bold])
let font = UIFont(descriptor: fontDescriptor, size: 17)
2025-06-30 15:25