NSTextField 개체의 테두리 색을 변경하고 싶습니다. 그러나이를 수행 할 수 없습니다.NSTextField 테두리 색 변경
은 이미 많은 솔루션 EX를 시도 : 배경을 그리는, 서브 클래스 ...
는 어떤 아이디어가이 문제를 해결하거나 공유 할 수있는 사람이 있습니까?알려 주시기 바랍니다. 많은 감사합니다.
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];
}
}
출력 :
@AviramNetanel 테두리와 배경이 동일하지 않습니다. –
내 솔루션이었다
[self.txtfield setBackgroundColor:[[NSColor redColor] colorWithAlphaComponent:0.5]];
당신은 다시 그것을 설정할 수 있습니다
[self.txtfield setBackgroundColor:[[NSColor grayColor] colorWithAlphaComponent:0.5]];
귀하의 솔루션은 국경을위한 것이 아닙니다. –
@ParagBafna - 알아. 그러나 그것은 또한 국경을 바꾼다. 그래서 나를 위해 그것은 충분했다. –
이 나를 위해 Parag의 대답은 그리기 이상한 텍스트 필드의 결과, 그래서 나는이 간단한 코드로 결국 (자신의 답변에 따라) :
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
if (!self.borderColor) {
return;
}
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];
[self.borderColor set];
[path stroke];
}
은 https : //developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html –