自定义TextField,要修改光标颜色,但是没有iOS textfield类似的tintColor属性,所以需要通过重载方法,修改光标颜色,具体的方法如下:
///修改textfield的光标颜色方法
-(BOOL) becomeFirstResponder
{
BOOL success = [super becomeFirstResponder];
if( success )
{
// Strictly spoken, NSText (which currentEditor returns) doesn't
// implement setInsertionPointColor:, but it's an NSTextView in practice.
// But let's be paranoid, better show an invisible black-on-black cursor
// than crash.
NSTextView* textField = (NSTextView*) [self currentEditor];
if( [textField respondsToSelector:@selector(setInsertionPointColor:)] )
{
NSColor*tintCor=Cor_Title;
[textField setInsertionPointColor: tintCor];
}
}
return success;
}
参考:https://stackoverflow.com/questions/2258300/nstextfield-white-text-on-black-background-but-black-cursor
网友评论