简体   繁体   English

如何在可可中自定义NSTextField外观(使用的字体,字体大小)?

[英]How to customize NSTextField look (Font used, font size) in Cocoa?

I'm making a Cocoa application and I can't figure out how to do something. 我正在制作可可应用程序,但我不知道该怎么做。

I want to make an NSTextField with a custom look like the one in Wallet : 我想制作一个自定义的NSTextField,就像Wallet中的那个:

Wallet screenshot. 钱包截图。

I figured out how to change the NSTextField size but I don't know how to change the font and it size. 我想出了如何更改NSTextField的大小,但我不知道如何更改字体及其大小。 I subclassed NSTextFieldCell like this but it doesn't work, the font is not changed if I don't choose a system font and the size only change line height but not characters height. 我像这样子类化了NSTextFieldCell,但是它不起作用,如果我不选择系统字体,则字体不会更改,并且大小只会更改行高,而不会更改字符高度。

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

To change the font of an NSTextField, change its font in Interface Builder using the Font Panel, or via -setFont: at runtime. 要更改NSTextField的字体,请在运行时使用“字体面板”或通过-setFont:在Interface Builder中更改其字体。

It is not necessary to subclass NSTextField or NSTextFieldCell simply to use a different font. 不必仅使用其他字体就可以将NSTextField或NSTextFieldCell子类化。

[label setFont:[NSFont fontWithName:@"Arial-BoldItalicMT" size:20]];

setFont:NSControlNSTextField超类中声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM