Nella versione iOS 5 della mia app ho avuto:testo align utilizzando drawInRect: withAttributes:
[self.text drawInRect: stringRect
withFont: [UIFont fontWithName: @"Courier" size: kCellFontSize]
lineBreakMode: NSLineBreakByTruncatingTail
alignment: NSTextAlignmentRight];
Sto passando per iOS 7. Il metodo di cui sopra è deprecato. Ora sto usando drawInRect: withAttributes:. Il parametro attributi è un oggetto NSDictionary. Posso ottenere drawInRect: withAttributes: a lavorare per l'ex parametro di carattere utilizza questo:
UIFont *font = [UIFont fontWithName: @"Courier" size: kCellFontSize];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: font, NSFontAttributeName,
nil];
[self.text drawInRect: stringRect
withAttributes: dictionary];
Cosa coppie chiave-valore si aggiunge a dizionario per ottenere NSLineBreakByTruncatingTail e NSTextAlignmentRight?
Come hai trovato questo? +1 – ViruMax
Anche se non riesco a capire una variazione più breve - questo funziona sicuramente, ma sembra un lavoro da assegnare solo per aggiungere qualche giustificazione! –
Come posso creare una stringa multi linea? –