desidero tracciare una linea personalizzabile all'interno di un UITextView
costituito da un testo (utilizzando NSAttributedString
)Tracciare una linea all'interno di un UITextView - NSAttributedString
Ecco quello che ho cercato
NSString *unicodeStr = [NSString stringWithFormat:@"%C%C%C", 0x00A0, 0x0009, 0x00A0]; //nbsp, tab, nbsp
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:unicodeStr];
NSRange strRange = NSMakeRange(0, str.length);
NSMutableParagraphStyle *const tabStyle = [[NSMutableParagraphStyle alloc] init];
tabStyle.headIndent = 16; //padding on left and right edges
tabStyle.firstLineHeadIndent = 16;
tabStyle.tailIndent = -16;
NSTextTab *listTab = [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentCenter location:40 options:@{}]; //this is how long I want the line to be
tabStyle.tabStops = @[listTab];
[str addAttribute:NSParagraphStyleAttributeName value:tabStyle range:strRange];
[str addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:2] range:strRange];
Ma non importa quale valore I fornire la posizione di tabulazione (40 in questo caso) e tailIndent (-16 qui), la linea rispetta solo l'headIndent e copre l'intera larghezza di UITextView (meno il valore headIndent, ovviamente).
EDIT - Sono abbastanza sicuro che il problema è perché non sto utilizzando i caratteri Unicode corretti (anche se sembrano essere la scelta logica). Nel caso questo dia a qualcuno un suggerimento, se aggiungo uno spazio dopo il 2 nbsp, cioè verso la fine, la scheda è limitata a una singola lunghezza di tabulazione
Puoi fornire un esempio di come desideri che il testo sia simile? –
Sto tentando di implementare un tag hr (regola orizzontale). Non sono supportati da NSAttributedString durante la conversione da html – lostInTransit