Sembra su iOS 8.0 (12A365) NSMutableAttributedString
a volte non verrà visualizzato correttamente. Il problema si verifica ovviamente quando l'intervallo dell'attributo non inizia all'inizio del testo (e se non vi sono altri attributi che iniziano all'inizio del testo). !Visualizzazione NSMutableAttributedString su iOS 8
Così con 1.) la seconda parola "verde" non mostrerà lo sfondo verde (bug) ("cella" è una UITableViewCell
con UILabel
"etichetta" come una visualizzazione secondaria):
1.)
text = [[NSMutableAttributedString alloc] initWithString:@"Green is green. (-> Bug)"];
[text addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:(NSRange){9,5}];
cell.label.attributedText=text
Con 2.) e 3.) gli sfondi vengono visualizzati correttamente:
2.)
text = [[NSMutableAttributedString alloc] initWithString:@"Green is green. (-> Ok)"];
[text addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:(NSRange){0,5}];
[text addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:(NSRange){9,5}];
cell.label.attributedText=text
3.)
text = [[NSMutableAttributedString alloc] initWithString:@"Green is green. (-> Ok)"];
[text addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:(NSRange){0,5}];
cell.label.attributedText=text
Trova screenshot e XCode 6 Progetto qui: Screenshot and XCode 6 Project
Sembra per me come un bug in iOS 8 - in modo da un rapporto continua ad Apple.
ho b anche vedere questo con il tentativo di sottolineare una porzione di etichetta. Questa è una regressione davvero fastidiosa. –
@Darcy: Grazie per il tuo commento. Puoi provare ad aggiungere un altro attributo dummy (come lo sfondo colorato chiaro ...) a (NSRange) {0,1} - per me questa è una soluzione alternativa per 1.) come menzionato sopra. –
Hai inviato una segnalazione di bug ad Apple? Sto correndo nello stesso identico problema qui. – MrBr