gpt4 book ai didi

ios - 如何使用 Objective C 提取 html 字符串并将其添加到 Xcode 中的 UILabel 中?

转载 作者:行者123 更新时间:2023-11-29 01:02:49 24 4
gpt4 key购买 nike

  1. 我有一个像这样的 HMTL 字符串:

ក្នុងសម័យ​អធិរាជ Emperor Meiji ដែល​ឡើងកាន់​អំណាច​ក្នុង​ឆ្នាំ ១៨៦៨ ព្រះអង្គ​បានទទួល​យក​សិទ្ធិ​គ្រប់គ្រង​ប្រទេស​ពេញលេញ ដែល​ផ្ដល់​ដោយ​ស្ដេចត្រាញ់​គ្រប់គ្នា​នៅ​ទូទាំង<!--more-->ប្រទេស ហើយ​ក្នុង​គ្រា​នោះដែរ​ព្រះអង្គ​បាន​ខិតខំ​ពង្រឹង​អាណាចក្រ​ជប៉ុន​ឲ្យ​មាន​ភាពរឹងមាំ ...<div><img width="624" height="353" src="https://www.pmhotnews.com/wp-content/uploads/2016/04/B20-24-0416-16-624x353.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="B20-24-0416 (16)" /></div><br />[more] ➥<i>ប្រភពពីគេហទំព័រ <strong>ប្រជាប្រិយ</strong> - <a href="https://www.pmhotnews.com/2016/04/23/56901.html/" target="_blank">រូបថត​ដ៏​កម្រ​របស់​សាមូរ៉ៃ​ជប៉ុន​ក្នុង​កំលុង​ឆ្នាំ ១៨០០ ដែល​ធ្លាប់តែ​ឮឈ្មោះ​តែ​មិនដែល​បានឃើញ​</a>​​</i>

  1. 我有一个像这样的 UILabel:

    UILabel * contentLabel = [[UILabel alloc] init];
  2. 如何使用 Objective-C 代码将文本设置为带有可点击事件的 contentLabel

最佳答案

NSString * strHtmlString = @"Your HTML String";

NSAttributedString * strAttrib = [[NSAttributedString alloc] initWithData:[strHtmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

contentLabel.attributedText = strAttrib;

希望这对你有帮助:)

关于ios - 如何使用 Objective C 提取 html 字符串并将其添加到 Xcode 中的 UILabel 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36809287/

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