在属性列表中,我有一个这样的字符串:
<string>A |picture| is worth *1000\* words.</string>
显然“图片”应该是斜体,“1000”应该是粗体。我正在尝试使用OHAttributedLabel显示文字:
NSString *theString = [pListData objectForKey:@"theString"];
NSMutableAttributedString* attrStr = [OHASBasicMarkupParser attributedStringByProcessingMarkupInString:theString];
self.myLabel.attributedText = attrStr; //self.myLabel is a UILabel
这就是我得到的:
为什么属性字以较小的字体显示,我该如何解决?
答案 0 :(得分:1)
我以前处理过这样的事情。所以,这会对你有所帮助。我也为你测试过并且工作正常:)
NSString *string = @"A |picture| is worth *1000* words.";
// Create an NSMutableAttributedString in order to be able to use the NSAttributedString+Attributes.h category
NSMutableAttributedString *attributedString = [NSMutableAttributedString attributedStringWithString:string];
// If using custom fonts, import all styles in the app and update the plist file
[attributedString setFont:[UIFont fontWithName:@"Helvetica" size:20.0]];
// Parse the markup and set the attributedText of the UILabel instance (no need to use the OHAttributedLabel subclass)
attributedString = [OHASBasicMarkupParser attributedStringByProcessingMarkupInAttributedString:attributedString];
label.attributedText = attributedString;
编辑:在调用-setFont:
之后使用-attributedStringByProcessingMarkupInAttributedString
时出现问题,因为这会重置解析过程中完成的所有工作。