[英]How to make NSTextField use custom subclass of NSTextFieldCell?
I've been looking for a solution to make my NSTextField bottom-aligned and I've found this and adjusted it for my needs. 我一直在寻找一个解决方案,使我的NSTextField底部对齐,我发现了这个,并根据我的需要进行了调整。 So now I have this custom NSTextFieldCell but how do I tell my NSTextFields to use this class (programmatically)?
所以现在我有了这个自定义的NSTextFieldCell但是如何告诉我的NSTextFields使用这个类(以编程方式)?
Since you ask how to do it programmatically, you can also use the setCellClass:
method on your NSTextField
subclass. 由于您询问如何以编程方式执行此操作,因此您还可以在
NSTextField
子类上使用setCellClass:
方法。 Call it in the load
or initialize
class methods: 在
load
或initialize
类方法中调用它:
+(void)load
{
[self setCellClass:[MyTextFieldCell class]];
}
It will not have any bearing on your text fields defined in Interface Builder, as the text field cell set there takes precedence. 它不会对Interface Builder中定义的文本字段产生任何影响,因为其中的文本字段单元格优先。
您是否尝试过NSCtrol类的setCell:方法?
- (void)setCell:(NSCell *)aCell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.