2015-05-15 17 views
6

Desidero copiare tutti gli attributi da uno NSMutableAttributedString in uno nuovo. Il codice che ho provato è questo:iOS - copia tutti gli attributi NSMutableAttributedString su un'altra NSMutableAttributedString

[attrStr enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, attrStr.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { 
     if (value) { 
      // UIFont *oldFont = (UIFont *)value; 
      UIFont *newFont = [_label.attributedText 
      [attrStr removeAttribute:NSFontAttributeName range:range]; 
      [attrStr addAttribute:NSFontAttributeName value:newFont range:range]; 
      //found = YES; 
     } 
    }]; 

il codice è chiaramente incompleta e sembra che il suo tentativo di farlo per solo font. Vorrei scorrere ogni attributo e aggiungerlo a una nuova variabile NSMutableAttributedString. Aggiornamento: la mia domanda è: come posso applicare tutti gli attributi di uno NSMutableAttributedString a un altro NSMutableAttributedString? Possiamo utilizzare questo metodo somehow:attribute:atIndex:effectiveRange

+0

Qual è la tua domanda? – Dima

+0

la mia domanda è: come posso applicare tutti gli attributi di una NSMutableAttributedString a un'altra NSMutableAttributedString? – j2emanue

+0

Vedere la mia risposta per il modo corretto di farlo. – Dima

risposta

-1

NSMutableAttributedString (e NSAttributedString) conforme alle NSCopying. Quindi dovresti essere in grado di farlo:

NSMutableAttributedString *mutableCopy = attrStr.mutableCopy; 
NSAttributedString *immutableCopy = attrStr.copy; 
+0

Mi piacerebbe copiare gli attributi non l'intero oggetto. Ad ogni modo, posso ottenere tutte le attribuzioni in un dizionario e poi copiarle su una nuova attribuita? – j2emanue

Problemi correlati