gpt4 book ai didi

ios - 属性字符串未正确采用 kern 值

转载 作者:行者123 更新时间:2023-11-30 10:52:16 24 4
gpt4 key购买 nike

如果我通过 -0.36,字距调整不起作用,如果我从 iPhone 截取屏幕截图并与设计进行比较,则字符串与长度不匹配。

func addCharacterSpacing(kernValue: Double = 1.15) {
if let labelText = text, labelText.count > 0 {
let attributedString = NSMutableAttributedString(string: labelText)
attributedString.addAttribute(NSAttributedString.Key.kern, value: kernValue, range: NSRange(location: 0, length: attributedString.length - 1))
attributedText = attributedString
}
}

最佳答案

最终创建了 @discardableResult 函数,该函数与 iPhone 的屏幕截图完全匹配并与设计进行比较。相应地传递参数。

@discardableResult func applyAttributesWithKerning(_ text: String, font:UIFont, lineSpace: CGFloat, charSpace: CGFloat, color:UIColor) -> NSMutableAttributedString {

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = lineSpace

var attrs: [NSAttributedString.Key: Any] = [NSAttributedString.Key.paragraphStyle: paragraphStyle]
attrs[NSAttributedString.Key.kern] = charSpace
attrs[NSAttributedString.Key.font] = font
attrs[NSAttributedString.Key.foregroundColor] = color
let boldString = NSMutableAttributedString(string:text, attributes: attrs)
append(boldString)

return self
}

关于ios - 属性字符串未正确采用 kern 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54330971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com