How to customize the look of an NSTextField (font used, font size) in Cocoa?

I am creating a Cocoa application and I cannot figure out how to do this.

I want to make an NSTextField with a custom view similar to the one in Wallet:

Wallet screenshot

I figured out how to resize NSTextField, but I don't know how to resize the font and its size. I have subclassed NSTextFieldCell, but this does not work, the font does not change unless I select the system font, and the size only changes the height of the line, but not the height of the characters.

Header file:

#import <Cocoa/Cocoa.h> @interface VLTextFieldCell : NSTextFieldCell { } @end 

Class file:

 #import "VLTextFieldCell.h" @implementation VLTextFieldCell - (NSFont *)font { return [NSFont fontWithName:@"Lucida Grande" size:16.0]; } @end 
+7
objective-c cocoa nstextfield macos
source share
2 answers

To change the font of an NSTextField, change its font in Interface Builder using the Font Panel or via -setFont: at run time.

There is no need to subclass NSTextField or NSTextFieldCell just to use a different font.

+14
source share
 [label setFont:[NSFont fontWithName:@"Arial-BoldItalicMT" size:20]]; 

setFont: declared in NSControl , the super class of NSTextField .

+5
source share

All Articles