Come è possibile utilizzare il font barrato nell'obiettivo C ??? In particolare in UITableViewCellCarattere strike-through nell'obiettivo C
cell.textLabel.text = name;
cell.detailTextLabel.text = quantity ;
cell.XXX = ??
Come è possibile utilizzare il font barrato nell'obiettivo C ??? In particolare in UITableViewCellCarattere strike-through nell'obiettivo C
cell.textLabel.text = name;
cell.detailTextLabel.text = quantity ;
cell.XXX = ??
EDIT: Questa risposta non è aggiornato come di iOS 6. Si prega di consultare le risposte più recenti sotto
Non c'è il supporto nativo per i font strike-through o sottolineare. Devi disegnare le linee te stesso sopra le viste per le etichette.
Questo è stupido dal momento che l'ispettore di font per IB ha opzioni per impostare strike-through e underline, ma questi vengono prontamente ignorati se si tenta di impostarli.
C'è la documentazione da qualche parte per sostenere questo? (Non che ne dubito, mi stavo solo chiedendo.) – Tim
@Tim, Oltre a ciò NSAttributedString e la Guida alla programmazione delle stringhe attribuite non esistono nei Riferimenti Dev Devio iPhone, no. La mancanza di documentazione è la migliore che posso fare. –
Ho mai provato a passare a strike-through in IB, ma è stato ignorato come hai detto tu. – wal
CGRect frame = sender.titleLabel.frame;
UILabel *strikethrough = [[UILabel alloc] initWithFrame:frame];
strikethrough.opaque = YES;
strikethrough.backgroundColor = [UIColor clearColor];
strikethrough.text = @"------------------------------------------------";
strikethrough.lineBreakMode = UILineBreakModeClip;
[sender addSubview:strikethrough];
Hai mai pensato di trovare il tuo font barrato e caricarlo da solo? Non è così difficile, basta aggiungere l'UIFont al file Info.plist e inserire il nome del carattere. Quindi puoi impostare manualmente il testo su quel nuovo carattere barrato.
Vedere questo post sul caricamento di caratteri personalizzati.
Eventuali suggerimenti sui font che vengono con barrato? – hatunike
1-Prendi la dimensione del testo che deve barrato
CGSize expectedLabelSize = [string sizeWithFont:cell.titleLabel.font constrainedToSize:cell.titleLabel.frame.size lineBreakMode:UILineBreakModeClip];
2-Creare una linea e aggiungerlo al testo
UIView *viewUnderline = [[UIView alloc] init];
viewUnderline.frame = CGRectMake(20, 12, expectedLabelSize.width, 1);
viewUnderline.backgroundColor = [UIColor grayColor];
[cell addSubview:viewUnderline];
[viewUnderline release];
questo è Marin, il autore del capitolo delle stringhe attribuito in "iOS6 di Tutorials".
Dal momento che iOS6 è in realtà un supporto nativo per una serie di attributi di testo diversi, tra cui strike-trogolo.
Ecco un breve esempio, che è possibile utilizzare per l'etichetta testo della cella:
NSDictionary* attributes = @{
NSStrikethroughStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle]
};
NSAttributedString* attrText = [[NSAttributedString alloc] initWithString:@"My Text" attributes:attributes];
cell.textLabel.attributedText = attrText;
Questo è tutto. In bocca al lupo!
ecco come hai messo in evidenza la tua etichetta. Ma ricordate, funziona solo dopo che iOS 6.0
NSNumber *strikeSize = [NSNumber numberWithInt:2];
NSDictionary *strikeThroughAttribute = [NSDictionary dictionaryWithObject:strikeSize
forKey:NSStrikethroughStyleAttributeName];
NSAttributedString* strikeThroughText = [[NSAttributedString alloc] initWithString:@"Striking through it" attributes:strikeThroughAttribute];
strikeThroughLabel.attributedText = strikeThroughText;
UIView *strikeView = [[UIView alloc] initWithFrame:ccr(0, 0, myLabel.bounds.size.width, 1)];
strikeView.backgroundColor = [UIColor redColor];
strikeView.center = ccp(myLabel.bounds.size.width/2, myLabel.bounds.size.height/2);
[myLabel addSubview:strikeView];
Barrato è possibile utilizzando NSStrikeThroughAttributes
e attributedText
di UILabel. Ecco la soluzione in Swift
let strikeThroughAttributes = [NSStrikethroughStyleAttributeName : 1]
let strikeThroughString = NSAttributedString(string: "Text of Label", attributes: strikeThroughAttributes)
strikeThroughLabel.attributedText = strikeThroughString
Questo colpirà l'intera cella. Nel caso in cui avete bisogno di apparire come attività completata:
CGSize size = cell.contentView.frame.size; // you'll draw the line in whole cell.
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15,size.height/2,size.width - 30, 1)];
line.backgroundColor = [UIColor grayColor]; // set your preferred color
[cell addSubview:line];
Si può indicare qualche altro valore in CGRectMake invece di 15 - è compensato da X. In questo caso è meglio quindi diminuire la larghezza per valore raddoppiato (in il mio caso è 15 * 2 = 30) per un aspetto gradevole.
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"];
[attributeString addAttribute:NSStrikethroughStyleAttributeName
value:@2
range:NSMakeRange(0, [attributeString length])];
yourLabel.attributedText = attributeString;
Pura magia! Grazie! –
è possibile selezionare la risposta corretta al fine di non indurre in errore gli utenti che venire a trovare una soluzione per colpire il testo attraverso –