如何在Swift中更改字母间距?
我想改变我的导航栏标题中的字母间距,但迄今为止我还没有成功。
提前致谢。
您可以通过代码传递标题string(“E xample”)或标签(\ t)或通过如下代码来设置标题:
let attributedString = NSMutableAttributedString(string: "Example") attributedString.addAttribute(NSKernAttributeName, value: CGFloat(1.4), range: NSRange(location: 0, length: 9))
然后,你分配给你的标题。
波纹pipefunction为我工作,希望这也可以帮助你
func setCharacterSpacig(string:String) -> NSMutableAttributedString { let attributedStr = NSMutableAttributedString(string: string) attributedStr.addAttribute(NSKernAttributeName, value: 1.25, range: NSMakeRange(0, attributedStr.length)) return attributedStr }