Я пытаюсь установить строку NSAttributed в UILabel, передав проверку строки следующим методом:
-(NSAttributedString *) returnRichTextForString:(NSString *) inputString {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[inputString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil];
NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
[paragrahStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:NSMakeRange(0, [attributedString length])];
return attributedString;
}
И я дал входную строку как: @"<body> <p>This is some text.</p> <center>This text will be center-aligned.</center> <p>This is some other text. </p> </body>";
Я ожидал, что текст внутри тега <center>...</center>
будет выровнен по центру. Но этого не происходит! Любым способом, кроме CSS?
В любом случае я не хочу устанавливать для атрибута
NSTextAlignmentCenter
значение UILabel.
Заранее спасибо...
<center>
удален в HTML5. Отсюда и эта проблема!? - person byJeevan   schedule 28.04.2015<div style="text-align:center">...</div>
на тег<center>
. - person byJeevan   schedule 20.08.2015