Con NSAttributedString, ho provato a creare testo all'interno di un triangolo come di seguito;Perché NSLineBreakByWordWrapping divide la parola?
http://postimg.org/image/rp9fukgaj/
Ho usato metodo "NSLineBreakByWordWrapping" per il testo adatta all'interno forma definita. Ma la prima parola di testo si divide e non sono riuscito a trovare una soluzione per questo. Voglio che il mio testo salti alla riga successiva invece di dividere. Come lo posso fare?
Sotto il codice che ho usato;
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor=[UIColor blackColor];
CTFontRef fontRef = CTFontCreateWithName((CFStringRef)@"HelveticaNeue-Regular", 15.0f, NULL);
NSMutableParagraphStyle* paragraph = [NSMutableParagraphStyle new];
paragraph.headIndent = 10;
paragraph.firstLineHeadIndent = 10;
paragraph.tailIndent = -10;
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
paragraph.alignment = NSTextAlignmentCenter;
paragraph.paragraphSpacing = 15;
NSDictionary *attrDictionary = [NSDictionary dictionaryWithObjectsAndKeys: (__bridge id)fontRef, (NSString *)kCTFontAttributeName, (id)[[UIColor whiteColor] CGColor], (NSString *)(kCTForegroundColorAttributeName),paragraph,NSParagraphStyleAttributeName, nil];
CFRelease(fontRef);
NSAttributedString *attString = [[NSAttributedString alloc] initWithString:@"Initially, now I create the paragraph style and apply it to the first character. Note how the margins are dictated: the tailIndent is negative, to bring the right margin leftward, and the firstLineHeadIndent must be set separately, as the headIndent does not automatically apply to the first line." attributes:attrDictionary];
[(CustomView *)[self view] setAttString:attString];
}
Poiché sai che la prima parola non va bene, inizia con un'interruzione di paragrafo per spostare tutto verso il basso. Puoi disegnare con il kit di testo e ignorare il gestore di layout, ovviamente, per evitare che ciò accada (o potresti lasciarlo sillabare). – matt