美文网首页
NSTextField设置光标颜色

NSTextField设置光标颜色

作者: devileatapple | 来源:发表于2021-10-22 14:49 被阅读0次

    自定义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

    相关文章

      网友评论

          本文标题:NSTextField设置光标颜色

          本文链接:https://www.haomeiwen.com/subject/scacaltx.html