使用 NSAttributedString,我尝试在三角形内创建文本,如下所示;
http://postimg.org/image/rp9fukgaj/
我使用“NSLineBreakByWordWrapping”方法在定义的形状内拟合文本。但是文本的第一个单词分裂了,我找不到解决方案。我希望我的文本跳转到下一行而不是拆分。我怎样才能做到这一点?
在我使用的代码下方;
- (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];
}