當我使用coretext時,我發現創建的字體在垂直方向systemfontofsize:上fontWithName: size:有不同的效果。我不知道這是否正常。感謝您的幫助。
systemfontofsize圖片:

fontWithName: size:圖片:

標簽代碼在這里:
@interface TestUILabel: UIView
@end
@implementation TestUILabel
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
// UIFont *font = [UIFont systemFontOfSize:16];
UIFont *font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
NSAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:@"hello world"
attributes:@{NSFontAttributeName: font,
NSForegroundColorAttributeName: UIColor.blackColor,
NSVerticalGlyphFormAttributeName: @(YES)
}];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)attributeStr);
CFRange rangeAll = CFRangeMake(0,attributeStr.length);
CFRange fitRange = CFRangeMake(0, 0);
CGSize s = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, rangeAll, nil, rect.size, &fitRange);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1, -1);
CGRect frameRect =CGRectMake((rect.size.width-s.height)/2.0, (rect.size.height-s.width)/2.0, s.height, s.width);
CGPathRef framePath = CGPathCreateWithRect(frameRect, nil);
NSDictionary *dic = @{(id)kCTFrameProgressionAttributeName:@(kCTFrameProgressionLeftToRight)};
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, rangeAll, framePath, (__bridge CFDictionaryRef)dic);
CTFrameDraw(frame, context);
}
@end
uj5u.com熱心網友回復:
Apple 指定NSVerticalGlyphFormAttributeName在 iOS 上未定義除水平之外的任何設定。也許這只是其中的一些副作用。
在 iOS 中,始終使用水平文本,并且未定義指定不同的值。
https://developer.apple.com/documentation/uikit/nsverticalglyphformattributename
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/451652.html
