3

在属性列表中,我有一个这样的字符串:

<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

这就是我得到的:

在此处输入图像描述

为什么属性词以较小的字体显示,我该如何解决?

4

1 回答 1

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,因为这会重置解析期间完成的所有工作。

于 2014-01-12T23:27:53.960 回答