gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:28:30 26 4
gpt4 key购买 nike

我想改变 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];
}
}

输出:

enter image description here

enter image description here

关于objective-c - 更改 NSTextField 的边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18568054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com