1

为什么这段代码只给了我一行?但是如果我写@“line1\n\0”,那么我将有两行!为什么 last '\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);

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

4

0 回答 0