Я использую attributedText
свойство label
для рендеринга html.NSAttributedString не передает html разрывы строк
Он отлично работает с визуализацией полужирным и курсивом. Однако, когда я пытаюсь отобразить разрывы строк html, он просто отключает весь текст, появляющийся после разрыва строки.
NSString* view = @"<i>Testing</i> and this is <b>bold</b> <br> This should be in next line";
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *preview = [[NSAttributedString alloc] initWithData:[view dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:nil];
self.labelView.attributedText = preview;
Помощь требуется
Может быть, вы пропустили NSUTF8StringEncoding для кодирования символов части, как показано здесь: http://stackoverflow.com/questions/4217820/convert-html-to-nsattributedstring-in -ios '[[NSAttributedString Alloc] initWithData: [HTMLString dataUsingEncoding: NSUTF8StringEncoding] опции: @ {NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @ (NSUTF8StringEncoding)} documentAttributes: ошибка ноль: ноль];' – Zhang
, что кодирование я должен использовать то поскольку html не будет веб-страницей, но будет в основном для форматирования текста –
Заменяет ли '@ {NSDocumentTypeDocumentAttribute: NSHTMLTextDoc umentType}; 'с' @ {NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @ (NSUTF8StringEncoding)}; 'help? – Zhang