CTFramesetterCreateWithAttributedString不创建最后一行

时间:2012-08-10 13:02:15

标签: objective-c ios

为什么这段代码只给我一行?但如果我写@“line1 \ n \ 0”,那么我将有两行!为什么最后'\ n'不创建新行?

CTFramesetterRef ctfsr = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)[[NSAttributedString alloc] initWithString:@"line1\n"]);
    CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(ctfsr, CFRangeMake(0, 0), NULL, CGSizeMake(width, CGFLOAT_MAX), NULL);
    CGRect tempRect = CGRectMake(0, 0, _textContentView.bounds.size.width, suggestedSize.height);
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:tempRect];
    CTFrameRef ctfr = CTFramesetterCreateFrame(ctfsr, CFRangeMake(0, 0), [path CGPath], NULL);
    NSArray* lines = (__bridge NSArray*)CTFrameGetLines(ctfr);
    NSLog(@"%@", lines);

如何在不添加任何符号的情况下创建新行?

0 个答案:

没有答案