2016-11-27 5 views

답변

0

나는 NSTextFieldCell를 서브 클래 싱하고 해당 분야 편집기로 NSTextTextView의 서브 클래스를 반환하게하여 해결 방법을 발견했다. 이 하위 클래스는 NO를 반환하는 - drawsBackground을 무시해야합니다. 초기화 후에이 속성을 설정하는 것으로 충분하지 않은 것 같습니다.

@interface NonBackgroundDrawingTextView : NSTextView 

@end 


@implementation NonBackgroundDrawingTextView 

- (BOOL)drawsBackground { 
    return NO; 
} 

@end 

@interface CustomTextFieldCell : NSTextFieldCell 

@end 

@implementation CustomTextFieldCell 

- (NSTextView *)fieldEditorForView:(NSView *)controlView { 
    static NSMutableDictionary* FieldEditors = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     FieldEditors = [NSMutableDictionary dictionary]; 
    }); 
    if (FieldEditors[@(controlView.hash)]) { 
     return FieldEditors[@(controlView.hash)]; 
    } 
    NSTextView* textView = [[NonBackgroundDrawingTextView alloc] initWithFrame:NSZeroRect]; 
    [textView setFieldEditor:YES]; 
    [textView setFocusRingType:NSFocusRingTypeExterior]; 
    FieldEditors[@(controlView.hash)] = textView; 
    return textView; 
} 

@end