[英]How to make bold font NSString value?
In my iOS application, how can I make bold font in NSString value?在我的 iOS 应用程序中,如何在 NSString 值中制作粗体字体? I used below code for making bold font text in NSString value, but showing error我使用下面的代码在 NSString 值中制作粗体文本,但显示错误
like this:像这样:
Undefined symbols for architecture i386: "_kCIAttributeName",架构 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]];
How do I make bold font in string?如何在字符串中制作粗体字体?
the NSString
is for store a simple texts without any font formatting. NSString
用于存储没有任何字体格式的简单文本。
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. UILabel
有一个font
属性,您可以使用它来设置UI
上可见文本的字体,但是UILabel
只能使用一种格式并且整个文本具有相同的字体和样式。
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.如果你真的想使用一种富文本文档,你应该创建一个UIWebView
类,你可以在里面显示任何带有标准HTML
标签的文档。
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... UILabel
可以存储自 iOS6 以来的属性字符串,这使您有机会在一个UILabel
实例中显示格式丰富的文本,甚至可以使用各种字体或大小等...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.