Bibi's DevLog ๐Ÿค“๐ŸŽ

UIFont Extension - custom font ๋ณธ๋ฌธ

๐Ÿ“ฑ๐ŸŽ iOS/Code Templates

UIFont Extension - custom font

๋น„๋น„ bibi 2022. 5. 11. 15:17

https://hryang.tistory.com/23

๋จผ์ € ์›ํ•˜๋Š” ํฐํŠธ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ๋ฐ›๊ณ , ํ”„๋กœ์ ํŠธ์— ํฌํ•จ์‹œํ‚ค๊ณ , Info.plist์— ๋“ฑ๋กํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์œ„ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.

์ดํ›„ ํฐํŠธ ํŒŒ์ผ์˜ ์ด๋ฆ„(ํ™•์žฅ์ž ์ œ์™ธ)์„ UIFont(name:)์œผ๋กœ ์ง€์ •ํ•œ๋‹ค.

import UIKit

enum CustomFont {
    case santanaBlack
}

extension UIFont {

    static func customFont(_ name: CustomFont) -> UIFont {

        switch name {
        case .santanaBlack: // set font and size you want
            return UIFont(name: "Santana-Black", size: 32) ?? UIFont()

        }
    }

}