相关疑难解决方法(0)

CTLineGetTypographicBounds的问题

代码是从SimpleTextInput sampe代码中提取的,稍作修改.

创建框架:

self.font = [UIFont systemFontOfSize:18.f];
CTFontRef ctFont = CTFontCreateWithName((CFStringRef) self.font.fontName, self.font.pointSize, NULL);        
self.attributes = [[NSDictionary dictionaryWithObject:(id)ctFont forKey:(NSString *)kCTFontAttributeName] retain];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:self.text attributes:self.attributes];    

_framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedString);

// Create the Core Text frame using our current view rect bounds
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
_frame =  CTFramesetterCreateFrame(_framesetter, CFRangeMake(0, 0), [path CGPath], NULL);
Run Code Online (Sandbox Code Playgroud)

线下面是帧(由获得的任何线CTFrameGetLines(_frame)):

CGFloat ascent, descent, leading;
CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
CGPoint origin;
CTFrameGetLineOrigins(_frame, CFRangeMake(i, 1), &origin);
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 从CTLineGetTypographicBounds或ctFont获得的上升是13.860352,而self.font.ascender是16.860352.这3点差异来自哪里? …

core-text ios

6
推荐指数
1
解决办法
2874
查看次数

标签 统计

core-text ×1

ios ×1