Name and size from NSFont

家住魔仙堡 提交于 2019-12-10 20:31:45

问题


i've tried to find something in the Internet, but right now I don't have an answer, so it would be great if you can help me! So far I have a NSFont object, but I would like the name (as NSString) and size of the font, so I can output that! It's like

[NSFont fontWithName:@"Menlo" size:11];

only backwards, so I get the name "Menlo" and as size 11.

Thanks for help! Xcoder from Germany


回答1:


The name and size of NSFont are variables with setters and getters (@property) so you can easily get them:

object.fontName;
object.systemSize;



回答2:


NSString* fontName = [*yourfont* fontName];
float fontSize = [[[*yourfont* fontDescriptor] objectForKey:NSFontSizeAttribute] floatValue];



回答3:


I think it's font.pointSize now, not font.systemSize.




回答4:


Fonts are just objects. They have variables like fontName and systemSize. For example if I wanted to know the font and size of a UILabel named titleLabel I would use:

NSLog(@"fontwithName:%@ size:%f", self.titleLabel.font.fontName, self.titleLabel.font.systemSize);

For more look at the NSFont Class Reference. https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSFont_Class/Reference/Reference.html



来源:https://stackoverflow.com/questions/9234587/name-and-size-from-nsfont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!