how to make bold font NSString value?

喜欢而已 提交于 2019-12-20 03:50:21

问题


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



来源:https://stackoverflow.com/questions/11648432/how-to-make-bold-font-nsstring-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!