how to make bold font NSString value?

2019-03-01 10:20发布

问题:

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

回答1:

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