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

前端之家收集整理的这篇文章主要介绍了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&C++相关文章