我正在使用UILabel(iOS7)中的字體,並且遇到了一些我希望有人可以解釋的東西: 字體的Glyph,Ascender和Descender之間的關係是什麼?iOS中字體Glyph Ascender和Descender之間的關係是什麼?
從我讀過的文檔中,Ascender是基線上方字體的一部分,下面是下面的部分(返回爲負值)。組合的絕對值應該是字體的最大高度。
例如255的伸部和-64下降部將給出319 的總高度然而銘文高度返回爲228.4
編輯:這裏的字形碼:
CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)(uiFont.fontName), uiFont.pointSize, NULL);
UniChar ch = [msgLabel.text characterAtIndex:0];
CGGlyph glyph;
if (CTFontGetGlyphsForCharacters (ctFont, &ch, &glyph, 1)) {
CGRect bounds = CTFontGetBoundingRectsForGlyphs (ctFont, kCTFontOrientationDefault, &glyph, nil, 1);
float glyphHeight = bounds.size.height;
}
而這裏的上升器/下降代碼:
float adHeight = myLabel.font.ascender-myLabel.font.descender; //Descender is always a negative value
那麼爲什麼從CTFontGetBoundingRectsForGlyphs返回的字形高度不等於Ascender plus Descender?
你怎麼得到字形高度?也許顯示一些代碼? – hooleyhoop
好的 - 添加了一些代碼... – wayneh