小编ser*_*nol的帖子

为什么NSLineBreakByWordWrapping分裂单词?

使用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 …
Run Code Online (Sandbox Code Playgroud)

line-breaks nsattributedstring ios

5
推荐指数
1
解决办法
517
查看次数

标签 统计

ios ×1

line-breaks ×1

nsattributedstring ×1