use*_*229 4 fonts cocoa objective-c
嘿伙计们,我试图从字体和字体大小中找到字符串的宽度(以像素为单位).我目前正在使用此代码,但它不是100%的工作时间.还有另一种方法吗?
NSSize textSize = [aTextLayer.string sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:@"Bank Gothic Medium", NSFontNameAttribute, [NSNumber numberWithFloat:aTextLayer.fontSize], NSFontSizeAttribute, nil]];
Run Code Online (Sandbox Code Playgroud)
NSAttributedString-size通过Application Kit Additions 授予方法.
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
@"Bank Gothic Medium", NSFontNameAttribute,
[NSNumber numberWithFloat:aTextLayer.fontSize], NSFontSizeAttribute,
nil];
NSAttributedString* attributedString = [[NSAttributedString alloc] initWithString:aTextLayer.string attributes:attributes];
NSSize size = attributedString.size;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4890 次 |
| 最近记录: |