Skip to content

Commit

Permalink
feat: UIFont extension 추가
Browse files Browse the repository at this point in the history
- preferred font를 확장하여 bold, italic을 손쉽게 적용할 수 있도록 extension 마련
  • Loading branch information
WhiteHyun committed Nov 14, 2023
1 parent 3a81024 commit 97023ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ public extension UIButton.Configuration {
default: break
}
button.configuration?.title = text
button.configuration?.font = UIFont(
descriptor: UIFont
.preferredFont(forTextStyle: .largeTitle)
.fontDescriptor.withSymbolicTraits(.traitBold)!,
size: 0
)
button.configuration?.font = .preferredFont(forTextStyle: .largeTitle, with: .traitBold)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// UIFont+preferredFont.swift
// DesignSystem
//
// Created by 홍승현 on 11/14/23.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import UIKit

public extension UIFont {
static func preferredFont(forTextStyle: TextStyle, with traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
let font = Self.preferredFont(forTextStyle: forTextStyle)
guard let descriptor = font.fontDescriptor.withSymbolicTraits(traits) else {
return font
}

return UIFont(descriptor: descriptor, size: 0)
}
}

0 comments on commit 97023ab

Please sign in to comment.