Name and size from NSFont
Asked Answered
L

4

3

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

Lollop answered 10/2, 2012 at 20:46 Comment(0)
W
-2

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

object.fontName;
object.systemSize;
Wafture answered 15/3, 2012 at 16:18 Comment(2)
Are you sure that NSFont really have a property with name systemSize? It doesn't work at all in 10.6 SDK. @JPed's answer works for me.Fabrizio
systemSize do not exist. At least not anymore.Soracco
B
13
NSString* fontName = [*yourfont* fontName];
float fontSize = [[[*yourfont* fontDescriptor] objectForKey:NSFontSizeAttribute] floatValue];
Boniface answered 13/2, 2012 at 17:54 Comment(0)
M
7

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

Merow answered 23/9, 2014 at 20:42 Comment(0)
B
0

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

Basophil answered 13/2, 2012 at 15:20 Comment(1)
Even the documentation linked above does not mention a systemSize property. The correct property is pointSize.Chaparro
W
-2

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

object.fontName;
object.systemSize;
Wafture answered 15/3, 2012 at 16:18 Comment(2)
Are you sure that NSFont really have a property with name systemSize? It doesn't work at all in 10.6 SDK. @JPed's answer works for me.Fabrizio
systemSize do not exist. At least not anymore.Soracco

© 2022 - 2024 — McMap. All rights reserved.