在iOS 7中调整字母间距 [英] Adjust letter spacing in iOS 7

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

问题描述

在iOS 7中,当使用新的从屏幕边缘滑动手势向后导航时,后退按钮(艺术家)的标题将变为粉红色(在下面的示例中)并具有常规字体粗细黑色,字体粗重。





在我看来,动画使用两个不同的标签来达到这个效果;随着对方逐渐消失,一个淡出。然而,Apple以某种方式调整了字体,使常规标签完美地覆盖了粗体,从而产生了在两种不同重量和颜色之间变形的单个标签的错觉。



他们是否只是调整了常规字体上的字母间距,使其与粗体字符匹配?在这种情况下,如何在iOS 7中实现? Text Kit是否有任何令人敬畏的功能,或者我应该怎么做?

解决方案

你可以像这样调整字母间距,使用 NSAttributedString



在Objective-C中:



< pre class =lang -c prettyprint-override> NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:@The Clash];
[attributionString addAttribute:NSKernAttributeName
value:@(1.4)
range:NSMakeRange(0,9)];

self.label.attributedText = attributedString;

在Swift中:

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

label.attributedText = attributedString

有关字距调整的更多信息,请参阅文字中的印刷概念编程指南



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


In iOS 7, when navigating back using the new swipe-from-edge-of-screen gesture, the title of the Back button ("Artists") fades from being pink (in the example below) and having regular font weight to being black and having bold font weight.

It seems to me that the animation uses two different labels in order to achieve this effect; one fading out as the other fades in. However, Apple has somehow adjusted the font so that the regular label perfectly overlays the bold one, thus creating the illusion of a single label morphing between two different weights and colors.

Have they simply adjusted the letter spacing on the regular font so that it matches onto the bold one? In that case, how would that be achieved in iOS 7? Does Text Kit have any awesome features for doing this or how should I go about it?

解决方案

You can adjust letter spacing like this, using NSAttributedString.

In Objective-C:

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

self.label.attributedText = attributedString;

In Swift:

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

label.attributedText = attributedString

More info on kerning is available in Typographical Concepts from the Text Programming Guide.

I don't think there's a TextKit feature that will automatically match font spacing between bold and regular text.

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

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