gpt4 book ai didi

ios - 解析标记时 OHAttributedLabel 的格式问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:05 24 4
gpt4 key购买 nike

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

<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

这是我得到的:

enter image description here

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

最佳答案

我以前遇到过这样的事情。所以,这会对你有所帮助。我也已经为你测试过并且工作正常:)

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;

编辑: 在调用 -attributedStringByProcessingMarkupInAttributedString 之后使用 -setFont: 时会出现问题,因为这会重置解析期间完成的所有工作.

关于ios - 解析标记时 OHAttributedLabel 的格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19849722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com