如何使粗体字体NSString值? [英] how to make bold font NSString value?

查看:163
本文介绍了如何使粗体字体NSString值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone应用程序开发的新手。我正在开发iPhone应用程序。在这个应用程序中,我想在NSString值中加粗字体。我怎么能做到这一点。我在下面的代码中使用了NSString值中的粗体字体。但是显示错误

像这样
架构i386的未定义符号:
_kCIAttributeName,

  NSString * boldFontName = [[UIFont boldSystemFontOfSize:12] fontName]; 
NSString * yourString = [NSString stringWithFormat:@%@%@%@,key,@:,@];
NSRange boldedRange = NSMakeRange(22,4);

NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:yourString];

[attrString beginEditing];
[attrString addAttribute:kCIAttributeName
value:boldFontName
range:bolddedRange];

[attrString endEditing];

NSString * string = [NSString stringWithFormat:@%@%@,attrString,[dic objectForKey:key]];

可以帮助我如何在字符串中加粗字体。

谢谢

解决方案

NSString 用于存储没有任何字体格式的简单文本
$ b

UILabel 有一个 font 属性,你可以使用它在 UI 上设置可见文本的字体,但是 UILabel 可以只使用一种格式,整个文本将获得相同的字体和样式。




if你真的想使用一种丰富的文本文档,你应该创建一个 UIWebView 类,你可以用标准 HTML显示任何文档


$ b

更新



UILabel 可以存储归因字符串,即使使用各种字体或大小等等,也可以在单个 UILabel 实例中显示丰富格式的文本。 ...


I am new in iPhone application development. i am developing now iPhone application. In this application i want make bold font in NSString value. How can i achieve this. I am used below code for making bold font text in NSString value. But showing error

like this Undefined symbols for architecture i386: "_kCIAttributeName",

NSString *boldFontName = [[UIFont boldSystemFontOfSize:12] fontName];
                         NSString *yourString =  [NSString stringWithFormat:@"%@%@%@",key,@":",@" "];
                         NSRange boldedRange = NSMakeRange(22, 4);

                         NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:yourString];

                         [attrString beginEditing];
                         [attrString addAttribute:kCIAttributeName 
                         value:boldFontName
                         range:boldedRange];

                         [attrString endEditing];

                         NSString *string = [NSString stringWithFormat:@"%@%@",attrString,[dic objectForKey:key]];

can you help me how to make bold font in string.

Thanks

解决方案

the NSString is for store a simple texts without any font formatting.

the UILabel has a font property, you can use it to set the visible text's font on the UI, but the UILabel can work with one format only and the whole text gets the same font and style.


if you really want to use a kind of rich text document, you should create a UIWebView class and you can show any document inside with the standard HTML tags.


UPDATE

the UILabel can store attributed string since iOS6, which gives you a chance to show rich-formatted text in one single UILabel instance, even using various fonts or sizes, etc...

这篇关于如何使粗体字体NSString值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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