我正在尝试将HTML格式的文本转换成一个NSAttributedString
,以便我可以在UITextView
中正确地格式化文本。我发现了DTCoreText,可以做到这一点,但是当我运行代码时,会出现错误。
我使用的代码:
NSData *data = [_storyContent dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *styledContent = [[NSAttributedString alloc]initWithHTMLData:data documentAttributes:nil];
_bodyTextView.attributedText = styledContent;
_storyContent
是一个NSString。
错误:
[__NSCFType textBlocks]: unrecognized selector sent to instance 0xb83b310
我可以如何获取内容并将其格式化为可读性较高的方式?
示例文本:
<p>May 28, 2014 — During his brief life, David Arapene Cuch, 1978-2007, accomplished many things. He was a scholar, completing a bachelor’s degree in economics at Westminster College and a Master of Public Administration at the University of Utah. At the time of his unexpected death, Cuch, who was believed to be the first Ute Indian to attend law school, was in his third year at the University of Utah S.J. Quinney College of Law. In addition to his academic accomplishments, Cuch also worked as a coordinator for a social justice nonprofit group, an assistant teacher in Salt Lake City and a summer camp youth counselor. During law school, he worked for the Legal Defender Association and Salt Lake Legal Issues.</p>
<p>On Friday, May 30, Cuch’s accomplishments will be celebrated by his family, representatives of the Ute Indian Tribe and the University of Utah at an 11:30 a.m ceremony in the Varsity Room on the sixth floor of the Rice-Eccles Stadium. During the memorial, Cuch’s brother, Cameron, will announce the David Arapene Cuch Endowed Scholarship Fund, which was created to provide financial support for members of the Ute Indian Tribe who follow David Cuch’s path by attending law school at the U. The scholarship is funded by David Cuch’s family and friends.</p>
<p>“David Arapene Cuch was a remarkable individual. His death at such a young age is a tragedy, but his legacy of commitment to community, to the rights and sovereignty of American Indians and to improving the world for all of humanity continues to inspire us. The generous scholarship, in his honor, will provide opportunity for students to realize their dreams,” said University of Utah President David Pershing.</p>
<p>In addition to Cameron Cuch and President David Pershing, Bob Adler, interim dean of the College of Law, Gordon Howell, chairman of the Ute Indian Tribe Business Committee, and Cuch’s parents, Forrest and Carla Cuch, will also speak. Utah tribal drummers and singers are scheduled to perform.</p>
<p>Contributions in David Cuch’s honor may be made to the David Cuch Scholarship care of the University of Utah S.J. Quinney College of Law Development Office, 332 S. 1400 East Room 101, Salt Lake City, Utah, 84112.</p>