简体   繁体   中英

How to make bold font NSString value?

In my iOS application, how can I make bold font in NSString value? I 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]];

How do I make bold font in string?

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM