How to make NSTextField use custom subclass of NSTextFieldCell?

梦想的初衷 提交于 2019-12-10 04:12:16

问题


I've been looking for a solution to make my NSTextField bottom-aligned and I've found this and adjusted it for my needs. So now I have this custom NSTextFieldCell but how do I tell my NSTextFields to use this class (programmatically)?


回答1:


Have you tried setCell: method of the NSControl class?

- (void)setCell:(NSCell *)aCell



回答2:


Since you ask how to do it programmatically, you can also use the setCellClass: method on your NSTextField subclass. Call it in the load or initialize class methods:

+(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.



来源:https://stackoverflow.com/questions/11293071/how-to-make-nstextfield-use-custom-subclass-of-nstextfieldcell

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