[swift] Swift FontBlaster를 사용하여 앱의 피커 뷰에 폰트를 적용하는 방법은?
- 먼저, 프로젝트에 FontBlaster를 추가해야 합니다. CocoaPods를 사용하신다면, Podfile에 다음을 추가하고 터미널에서
pod install
을 실행하세요:
pod 'FontBlaster'
-
Pod 파일을 사용하지 않는다면, FontBlaster를 수동으로 프로젝트에 추가하세요. 다음은 FontBlaster의 깃허브 저장소에서 다운로드할 수 있는 링크입니다: FontBlaster GitHub
-
프로젝트에 FontBlaster를 추가한 후, 사용하고자 하는 폰트 파일을 프로젝트에 추가하세요. 폰트 파일은
.ttf
나.otf
형식이어야 합니다. -
폰트 파일을 프로젝트에 추가한 후,
AppDelegate
파일에서application(_:didFinishLaunchingWithOptions:)
메서드에서 다음과 같이 폰트를 적용하세요:
import FontBlaster
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FontBlaster.blast()
return true
}
- 폰트를 적용하고자 하는 뷰 컨트롤러의
viewDidLoad()
메서드에서 다음과 같이 폰트를 설정하세요:
import UIKit
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 폰트 적용
if let font = UIFont(name: "YourFontName", size: 17) {
let textAttributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey.font: font]
yourPickerView.setTitleTextAttributes(textAttributes, for: .normal)
}
}
}
위의 코드에서 “YourFontName”을 사용하고자 하는 폰트의 이름으로 변경하세요. 또한, yourPickerView
는 실제 사용하고자 하는 피커 뷰의 객체로 변경해야 합니다.
이제 FontBlaster를 사용하여 앱의 피커 뷰에 폰트를 적용할 수 있습니다.