objective-c – 更改NSTextField的边框颜色

我想改变NSTextField对象的边框颜色,但是我无法实现.

我已经尝试了许多解决方案EX:被子类,绘制背景…

有没有人可以解决这个问题或分享任何想法?

请告诉我.非常感谢.

解决方法

使用 NSBezierPath
- (void)drawRect:(NSRect)dirtyRect
{
    NSPoint origin = { 0.0,0.0 };
    NSRect rect;
    rect.origin = origin;
    rect.size.width  = [self bounds].size.width;
    rect.size.height = [self bounds].size.height;

    NSBezierPath * path;
    path = [NSBezierPath bezierPathWithRect:rect];
    [path setlinewidth:2];
    [[NSColor colorWithCalibratedWhite:1.0 alpha:0.394] set];
    [path fill];
    [[NSColor redColor] set]; 
    [path stroke];

    if (([[self window] firstResponder] == [self currentEditor]) && [NSApp isActive])
    {   
        [NSGraphicsContext saveGraphicsstate];
        NSSetFocusRingStyle(NSFocusRingOnly);
        [path fill]; 
        [NSGraphicsContext restoreGraphicsstate];
    }
    else
    {
        [[self attributedStringValue] drawInRect:rect];
    }
}

输出

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...