如何在 Swift 中更改字母间距? [英] How to change letter spacing in Swift?

查看:34
本文介绍了如何在 Swift 中更改字母间距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改导航栏标题中的字母间距,但到目前为止还没有成功.

I'd like to change the letter spacing in the title of my navigation bar but I've had no success so far.

提前致谢.

推荐答案

一个很酷的 UILabel 扩展:

A cool extension for UILabel:

extension UILabel{
func setCharacterSpacing(_ spacing: CGFloat){
    let attributedStr = NSMutableAttributedString(string: self.text ?? "")
    attributedStr.addAttribute(NSAttributedString.Key.kern, value: spacing, range: NSMakeRange(0, attributedStr.length))
    self.attributedText = attributedStr
 }
}

用法:

label.setCharacterSpacing(4)

这篇关于如何在 Swift 中更改字母间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆