更改NSTextField的边框颜色 [英] Change border color of NSTextField
本文介绍了更改NSTextField的边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变NSTextField对象的边框颜色,但我不能实现它。
I want to change the border color of NSTextField object, but I can't achieve it.
我已经尝试过许多解决方案EX:是子类,绘制背景...
I already have tried many solutions EX: be subclass, draw background...
有没有人可以解决这个问题或分享任何想法?
is there anyone who can resolve this issue or share any ideas?
请让我知道。非常感谢。
Please let me know. Many thanks.
推荐答案
使用 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];
}
}
输出:
>
这篇关于更改NSTextField的边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文