How to increase the character spacing in UILabel

后端 未结 6 756
孤独总比滥情好
孤独总比滥情好 2020-12-23 21:23

I am creating an app in >=iOS6. And I want to change the character spacing in UILabel. I have added the custom font \"FUTURABT HEAVY\" in my app but the Character are too cl

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 21:50

    Here the code for Swift 5 with a handy extension :

    extension UILabel {
        func addCharactersSpacing(spacing: CGFloat, txt: String) {
            let attributedString = NSMutableAttributedString(string: txt)
            attributedString.addAttribute(NSAttributedString.Key.kern, value: spacing, range: NSRange(location: 0, length: txt.count))
            self.attributedText = attributedString
        }
    }
    

提交回复
热议问题