Строка NSAttributed с тегом `center` не работает

Я пытаюсь установить строку 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.

Заранее спасибо...


person byJeevan    schedule 28.04.2015    source источник
comment
Из stackoverflow.com /questions/1798817/ Я узнал, что тег <center> удален в HTML5. Отсюда и эта проблема!?   -  person byJeevan    schedule 28.04.2015
comment
Смотрите ссылку 1 . iosdevelopertips.com/objective-c/ 2. stackoverflow.com/questions/28816501 /   -  person Ashok Londhe    schedule 28.04.2015
comment
Можно исправить этой заменой: <div style="text-align:center">...</div> на тег <center>.   -  person byJeevan    schedule 20.08.2015


Ответы (1)


Решено заменой тега <center> на

<div style="text-align:center">...</div>

из w3schools больше не поддерживается в HTML5

введите здесь описание изображения

person byJeevan    schedule 16.02.2016