chaneeii / iOS-Study-Log

โœจ iOS์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•œ ๊ฒƒ๋“ค์„ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค โœจ
18 stars 0 forks source link

๐Ÿ”ก Custom Font๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฒ• #33

Open chaneeii opened 2 years ago

chaneeii commented 2 years ago

์ปค์Šคํ…€ ํฐํŠธ๋ฅผ ๋„ฃ์–ด์•ผํ•˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ–ˆ๋Š”๋ฐ, ์ž๊พธ ์•ˆ๋„ฃ์–ด์ ธ์„œ ์ด๋Ÿฐ์ €๋Ÿฐ ํ•ด๊ฒฐ์„ ํ†ตํ•ด ์ž˜ ๋„ฃ๋Š” ํŒ์„ ํฌํ•จํ•ด์„œ ์ž‘์„ฑํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.

0. ์šฐ์„  ํฐํŠธํŒŒ์ผ ์ค€๋น„ํ•˜๊ธฐ

ttf, otf ํŒŒ์ผ์„ ์ค€๋น„ํ•ด์˜จ๋‹ค!

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-08-27 แ„‹แ…ฉแ„’แ…ฎ 8 40 28

1. ํฐํŠธ ํŒŒ์ผ์„ ๋„ฃ๊ธฐ

โœ… Add to targets ์—์„œ ํ”„๋กœ์ ํŠธ๋ช…์„ ๊ผญ ์ฒดํฌํ•ด์ค˜์•ผํ•œ๋‹ค โœ… ์ด๊ฑด ๊ผญ ์•ˆํ•ด๋„ ๋˜๊ธดํ•˜๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ Create folder references ๋กœ ์ฒดํฌํ•ด์„œ์•ผ ํฐํŠธ๊ฐ€ ๋“ค์–ด๊ฐ”๋‹ค. (ํšŒ์ƒ‰ํด๋” ํŒŒ๋ž‘ํด๋” ์ฐจ์ด..๋‚˜์ค‘์— ๊ณต๋ถ€ํ•ด๋ด์•ผ๊ฒ ๋‹ค..!)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-08-27 แ„‹แ…ฉแ„’แ…ฎ 8 31 26

2. Info.plist ์—์„œ ํฐํŠธ ํŒŒ์ผ ๋“ฑ๋กํ•˜๊ธฐ

โœ… Fonts provided by application ์— ํฐํŠธ ํŒŒ์ผ๋ช…์„ ๊ทธ๋Œ€๋กœ ํ™•์žฅ์ž๊นŒ์ง€ ์ž…๋ ฅํ•ด์ค€๋‹ค!

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-08-27 แ„‹แ…ฉแ„’แ…ฎ 8 43 24

3. ํฐํŠธ์ ์šฉํ•˜๊ธฐ

์š”๋ ‡๊ฒŒ ๋ถˆ๋Ÿฌ์„œ ์‚ฌ์šฉํ•˜๋ฉด๋œ๋‹ค.

label.font = UIFont(name: "MavenProBold", size: 30)

๐Ÿ‘€ TIP) ํฐํŠธ์˜ ์ง„์งœ ์ด๋ฆ„์„ ์•Œ์•„๋ณด์ž

๊ทผ๋ฐ ์—ฌ๊ธฐ์„œ ํฐํŠธ๋ฅผ ์ ์šฉํ•˜๋Š”๋ฐ ํฐํŠธ๊ฐ€ ์ œ๋Œ€๋กœ ์ ์šฉ์ด ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์„ ์ˆ˜๋„ ์žˆ๋‹ค. ์ž๊พธ ํฐํŠธ๊ฐ€ ์•ˆ๋– ์„œ ์ฐพ์•„๋ณด๋‹ˆ ํŒŒ์ผ๋ช…์ด๋ž‘ ํฐํŠธ ์ง„์งœ ์ด๋ฆ„์ด ๋‹ฌ๋ผ์„œ ๊ทธ๋ ‡๋‹ค๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.

๊ทธ๋Ÿด๋•???? ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰์‹œ์ผœ์„œ ์ง„์งœ ํฐํŠธ์ด๋ฆ„์„ ํ™•์ธํ•ด๋ณด๋ฉด ๋œ๋‹ค!

UIFont.familyNames.sorted().forEach { familyName in
    print("*** \(familyName) ***")
    UIFont.fontNames(forFamilyName: familyName).forEach { fontName in
        print("\(fontName)")
    }
    print("---------------------")
}

-> ํŒŒ์ผ๋ช…์ด๋ž‘ ํฐํŠธ๋ช…์ด ๋‹ค๋ฅธ ๊ฑฐ ๋ฐœ๊ฒฌ แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-08-27 แ„‹แ…ฉแ„’แ…ฎ 8 48 42

references

https://velog.io/@minji0801/iOSSwift-Custom-Font-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0-%EC%95%B1-%EB%82%B4-%ED%8F%B0%ED%8A%B8-%EB%B3%80%EA%B2%BD-%EA%B8%B0%EB%8A%A5

chaneeii commented 2 years ago

Font Extension ๋งŒ๋“ค๊ธฐ

๋ฐฉ๋ฒ•1

import UIKit

protocol Font {
    func of(size: CGFloat) -> UIFont?
}

extension Font where Self: RawRepresentable, Self.RawValue == String {
    func of(size: CGFloat) -> UIFont? {
        return UIFont(name: rawValue, size: size)
    }
}

enum MavenPro: String, Font {
    case bold = "MavenProBold"
    case black = "MavenProBlack"
}

์‚ฌ์šฉ์‹œ

$0.font = MavenPro.bold.of(size: 30)

๋ฐฉ๋ฒ•2

extension UIFont {

    enum Family: String {
        case Black, Bold, Light, Medium, Regular, Thin
    }

    static func roboto(size: CGFloat = 10, family: Family = .Regular) -> UIFont {
        return UIFont(name: "Roboto-\(family)", size: size)!
    }
}

์‚ฌ์šฉ์‹œ

let robotoBlack = UIFont.roboto(size: 10, family: .Black)
chaneeii commented 1 year ago

Tuist์—์„œ Font ์ถ”๊ฐ€ ์•ˆ๋˜๋Š” ๋ฌธ์ œ