ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

 

 

์ด๋ ‡๊ฒŒ ๋””์ž์ด๋„ˆ๊ฐ€ -3%์˜ ์ˆ˜์น˜๋กœ ์ž๊ฐ„์„ ์คฌ์„๋•Œ,

code๋กœ UILabel์˜ ์ž๊ฐ„์„ ์ˆ˜์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

 

๋””์ž์ด๋„ˆ์ž…์žฅ์—์„œ ์ด๋Ÿฐ ๋””ํ…Œ์ผ์„ ์•„์ฃผ ์ค‘์š”์‹œ ํ•˜๊ธฐ๋•Œ๋ฌธ์—

๊ฐœ๋ฐœ์ž์˜ ๋ˆˆ์—๋Š” ๋ณ„ ์ฐจ์ด๊ฐ€ ์—†๋”๋ผ๋„ ๊ทธ๋ƒฅ ๋„˜์–ด๊ฐˆ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค~

 

 

self.font.pointSize ๋กœ

UILabel๋งˆ๋‹ค ๋‹ค๋ฅธ font ์‚ฌ์ด์ฆˆ์— ์ ‘๊ทผํ•ด์ค„ ์ˆ˜ ์žˆ์–ด์š”. (default๋Š” -3%)

 

extension UILabel {
    func addCharacterSpacing(_ value: Double = -0.03) {
        let kernValue = self.font.pointSize * CGFloat(value)
        guard let text = text, !text.isEmpty else { return }
        let string = NSMutableAttributedString(string: text)
        string.addAttribute(NSAttributedString.Key.kern, value: kernValue, range: NSRange(location: 0, length: string.length - 1))
        attributedText = string
    }
}

 

 

 

๊ทธ๋ฆฌ๊ณ 

๊ณ ์ • ์ˆ˜์น˜๋กœ ์ฃผ๊ณ ์‹ถ์œผ์‹ ๋ถ„์€

์ด๋ ‡๊ฒŒ.. (default๋Š” 0.5)

 

extension UILabel {
    func addCharacterSpacing(kernValue:Double = 0.5) {
        guard let text = text, !text.isEmpty else { return }
        let string = NSMutableAttributedString(string: text)
        string.addAttribute(NSAttributedString.Key.kern, value: kernValue, range: NSRange(location: 0, length: string.length - 1))
        attributedText = string
    }
}

 

๊ทธ๋ฆฌ๊ณ  ์ ์šฉ์€ UILabel์— lbl.addCharacterSpacing().

 

 

 

 

+ ๐Ÿฏ TIP

 

code๋กœ ui๋ฅผ ์ž‘์„ฑํ•˜๋‹ค๋ณด๋ฉด ํ•ญ์ƒ ์„ ์–ธํ•ด์•ผํ•˜๋Š” ์†์„ฑ๋“ค์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

 

 

๊ฐ„๋‹จํ•˜๊ฒŒ ๋‹จ์ถ•ํ‚ค๋ฅผ ์ด์šฉํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ ์ด๋ ‡๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€

๋‹จ์ถ•ํ‚ค๋ฅผ ๋งŒ๋“ค๊ณ ์ž ํ•˜๋Š” ๋‚ด์šฉ์„ ๋“œ๋ž˜๊ทธ ํ•œ ๋’ค ์šฐํด๋ฆญ,

create code snippet.

 

 

and then,

 

 

๋‹จ์ถ•ํ‚ค๋Š” ์ €๋Š” uilb ๋ผ๊ณ  ์„ค์ •ํ•ด์คฌ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  ์ €๊ธฐ ํšŒ์ƒ‰ ๋ฐฐ๊ฒฝ์˜ ์ž…๋ ฅ ์œ ๋„ text๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์€ <# text #> ํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

UILabel์˜ ๋ณ€์ˆ˜๋ช…๊ณผ text ๋‚ด์šฉ์„ ๋ฐ”๋กœ ์ž…๋ ฅ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•ด์คฌ์Šต๋‹ˆ๋‹ค.

 

 

 

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

 

๋Œ“๊ธ€