2015-04-08 2 views
0

Я создаю NSAttributedString из HTML, как это делается.NSAttributedString, не отображающий отступ абзаца

decodedString = [[NSAttributedString alloc] initWithData:[encodedString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil]; 

Когда я отображаю строку в UITextView, все отображается хорошо, за исключением абзацев абзаца.

HTML, который преобразовывается в NSAttributedString.

"<div><div class=\"article-content\">\n\t\t\t\t\t<p class=\"p1\"><a href=\"http://9to5mac.com/2015/04/08/apple-watch-ship-times-4-to-6-weeks-may-for-edition/apple_watch_liefer1/\" rel=\"attachment wp-att-373515\"><img title=\"Apple online store leaks Watch ship times: 4-6 weeks for some Watch models, &#x2018;May&#x2019; for Edition\" class=\"alignnone size-full wp-image-373515\" src=\"https://9to5mac.files.wordpress.com/2015/04/apple_watch_liefer1.jpg?w=704\" alt=\"apple_watch_liefer1\" width=\"320.000000\"></a></p>\n<p class=\"p1\"><span class=\"s1\">Apple Watch goes up for preorder on April 10 and becomes available April 24 through retail stores and online, but some of Apple&#x2019;s online stores are listing ship dates ranging from April 24th to sometime in May depending on the model. </span></p>\n<p class=\"p1\"><span class=\"s1\">Earlier today some of Apple&#x2019;s online stores, including its German and UK stores, listed various shipping dates for the device for those willing to do a little digging on the site. While the Sport models and Apple Watch with classic leather strap and Milanese bracelet are listed as shipping between April 24th and May 8th, other models are listed as shipping in 4-6 weeks or simply in &#x201C;May&#x201D;. </span></p>\n<p class=\"p1\"><span class=\"s2\"><a href=\"http://macerkopf.de\">macerkopf.de</a></span><span class=\"s1\"> first spotted the shipping dates on the German Apple online store and we later spotted the same dates on the UK and other international stores:</span>\n\t\t\t</p>\n\t\t\n\n<p>Apple Watch Sport: Usually ships &#x201C;24.04. to 5.8. &#x201D;<br>\nApple Watch with modern leather bracelet: Usually ships in &#x201C;4 to 6 weeks&#x201D;<br>\nApple Watch Link Watch: Usually ships in &#x201C;4 to 6 weeks&#x201D;<br>\nApple Watch with leather strap with loop: Usually ships in &#x201C;4 to 6 weeks&#x201D;<br>\nApple Watch with classic leather strap: Usually ships &#x201C;24.04. to 5.8. &#x201D;<br>\nApple Watch with Milanese bracelet: Usually ships &#x201C;24.04. to 5.8. &#x201D;<br>\nApple Watch with Sport Armband: Usually ships</p>\n<p class=\"p1\"><span class=\"s1\">It&#x2019;s unclear if these dates will apply to the US or just international markets, but it&#x2019;s not surprising considering we&#x2019;ve heard Apple Watch stock could be limited at launch. In addition to limiting stock of the gold Watch Edition and the <a href=\"http://9to5mac.com/2015/03/30/apple-watch-faq-preorders-try-on-appointments/\" target=\"_blank\">number of units customers can buy from each collection</a>, we reported earlier this month that <a href=\"http://9to5mac.com/2015/04/03/applecare-for-apple-watch-999-for-edition-79-for-watch-59-for-sport/\"><span class=\"s2\">supplies of the rose gold Edition models will be very tight</span></a> as Apple continues to work out discoloration issues.</span></p>\n<p class=\"p1\">You can get all the details on how preordering and purchasing the Apple Watch will work <a href=\"http://9to5mac.com/2015/03/30/apple-watch-faq-preorders-try-on-appointments/\" target=\"_blank\">in our FAQ here</a>.</p>\n<div id=\"jp-post-flair\" class=\"sharedaddy sd-like-enabled\"><div class=\"sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded\" id=\"like-post-wrapper-22754319-373514-55255999c6ac5\"><h3 class=\"sd-title\">Like this:</h3><p class=\"likes-widget-placeholder post-likes-widget-placeholder\"><span class=\"button\"><span>Like</span></span> <span class=\"loading\">Loading...</span></p><a class=\"sd-link-color\"></a></div></div>\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\n\n\t\n\n\t\n\n\t\n\n\t\t\t\t</div>\n\t\t\t</div>" 

Выполнение некоторых исследований я узнал, что </p> кодов для космических полей до и после абзацев. Я предполагаю, что AttributedString не «понимает» это или что-то еще.

Должно ли NSAttributedString понимать </p>?

Почему это происходит?

Как это исправить?

Спасибо!

ответ

1

<p> теги просто определяют абзацы текста. Они не форматируют абзац в смысле отступов первой строки, если это то, о чем вы говорите.

Вот пример того, как будет выглядеть ваш HTML-код, обратите внимание, что абзацы не отступают.

Пример:

https://jsfiddle.net/yoegpuxe/

Попробуйте ввести в \t перед каждым пунктом, если это то, что вы ищете.

Смежные вопросы