gpt4 book ai didi

ios7 - 在 iOS 7 中调整字母间距

转载 作者:行者123 更新时间:2023-12-03 01:17:25 24 4
gpt4 key购买 nike

在 iOS 7 中,当使用新的从屏幕边缘滑动手势返回时,“后退”按钮的标题(“艺术家”)会从粉红色(在下面的示例中)淡出并具有常规字体粗细为黑色且字体粗细。

enter image description here

在我看来,动画使用了两个不同的标签来实现这种效果;一个淡出,另一个淡入。不过,Apple 以某种方式调整了字体,使常规标签完美地覆盖粗体标签,从而产生单个标签在两种不同粗细和颜色之间变形的错觉。

他们是否只是简单地调整了常规字体上的字母间距,使其与粗体字体相匹配?那么,在 iOS 7 中如何实现这一点呢? Text Kit 是否有任何很棒的功能可以做到这一点,或者我应该如何去做?

最佳答案

您可以使用 NSAttributedString 来调整字母间距。

在 Objective-C 中:

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"The Clash"];
[attributedString addAttribute:NSKernAttributeName
value:@(1.4)
range:NSMakeRange(0, 9)];

self.label.attributedText = attributedString;

在 Swift 3 中:

let attributedString = NSMutableAttributedString(string: "The Clash")
attributedString.addAttribute(NSKernAttributeName, value: CGFloat(1.4), range: NSRange(location: 0, length: 9))

label.attributedText = attributedString

在 Swift 4 及更高版本中:

label.attributedText = NSAttributedString(string: "The Clash", attributes: [.kern: 1.4])

有关字距调整的更多信息可在 Typographical Concepts from the Text Programming Guide 中找到。 .

我认为 TextKit 功能不会自动匹配粗体文本和常规文本之间的字体间距。

关于ios7 - 在 iOS 7 中调整字母间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21140683/

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