//设置字体样式和大小
NSFont *font =[NSFont fontWithName:@"Helvetica" size:fontsize];
NSString*strTemp = @"TEST";
NSDictionary*attributes = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,[NSColor yellowColor], NSForegroundColorAttributeName,nil];
NSAttributedString* currentText=[[NSAttributedString alloc] initWithString:strTemp attributes:attributes];
NSSizeattrSize = [currentText size];
int pixelsWith= attrSize.width;
intpixelsHight = attrSize.height;
本文通过一个具体的示例介绍了如何使用 NSAttributedString 来设置文本的字体和颜色属性。通过创建自定义字体和颜色,可以为字符串设置特定的样式,并获取该样式的尺寸信息。
1675

被折叠的 条评论
为什么被折叠?



