2016-11-27 52 views
1

黑色文本背景我注意到macOS 10.12下的一個問題:當我創建一個帶有「源列表」的NSTableView突出顯示樣式時,文本單元格繪製黑色背景編輯,使文本黑色黑色,實際上不可讀。基於單元格的NSTableView與黑名單高亮樣式(10.12)

我想知道是否有其他人遇到這個問題,以及是否有可能的解決方法。

enter image description here

回答

0

我已經通過繼承NSTextFieldCell並使其返回NSTextTextView一個子類作爲其字段編輯器找到了一個解決方法。 該子類需要覆蓋- drawsBackground返回NO。 初始化後設置此屬性似乎不夠。

@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 
相關問題