objective-c – 更改NSTextField的边框颜色
发布时间:2020-12-16 03:44:38 所属栏目:百科 来源:网络整理
导读:我想改变NSTextField对象的边框颜色,但是我无法实现. 我已经尝试了许多解决方案EX:被子类,绘制背景… 有没有人可以解决这个问题或分享任何想法? 请告诉我.非常感谢. 解决方法 使用 NSBezierPath - (void)drawRect:(NSRect)dirtyRect{ NSPoint origin = { 0
我想改变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]; } } 输出: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |