gpt4 book ai didi

ios - 为什么 NSLineBreakByWordWrapping 拆分单词?

转载 作者:可可西里 更新时间:2023-11-01 04:59:10 24 4
gpt4 key购买 nike

通过使用 NSAttributedString,我尝试在三角形内创建文本,如下所示;

http://postimg.org/image/rp9fukgaj/

我使用“NSLineBreakByWordWrapping”方法在定义的形状内调整文本。但是文本的第一个词 split 了,我找不到解决方案。我希望我的文本跳转到下一行而不是拆分。我该怎么做?

下面是我用的代码;

- (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];
}

最佳答案

查看 documentation对于 NSLineBreakMode,显然如果该词不适合给定的行,该词将被分解以适合。如果你的文本是静态的,你可以只插入一个换行符来跳过三角形的第一部分;否则,您将不得不聪明地弄清楚如何克服这个限制。

关于ios - 为什么 NSLineBreakByWordWrapping 拆分单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18208953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com