如何增加UILabel中的字符间距 [英] How to increase the character spacing in UILabel

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

问题描述

我正在> = iOS6中创建一个应用。我想改变UILabel中的字符间距。我在我的应用程序中添加了自定义字体FUTURABT HEAVY但字符太靠近了。

I am creating an app in >=iOS6. And I want to change the character spacing in UILabel. I have added the custom font "FUTURABT HEAVY" in my app but the Character are too close to eachother.

我找到了好的代码这里增加字符间距。但是如果我试图改变它而不是我的文字变成左对齐而不是中心。

I have find the good code here to increase the character spacing. But if i tried to change it than my text became left- align in stead of center.

请帮我解决这个问题。

推荐答案

你应该使用 NSAttributedString NSKernAttributeName 属性

以下是一个小例子:

UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];

NSString *string = @"Some important text";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];

float spacing = 5.0f;
[attributedString addAttribute:NSKernAttributeName
            value:@(spacing)
            range:NSMakeRange(0, [string length])];

label.attributedText = attributedString;
[self.view addSubview:label];

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

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