2011-07-04 3 views
2

NSAutlineView를 NSAttributedString을 사용하여 포맷 한 데이터로 채 웁니다. 지금까지 텍스트 글꼴, 크기 및 색상의 서식을 지정했습니다. 내 문제는 행을 선택하면 전경색이 변경되지 않는다는 것입니다. NSTextFieldCell을 만들고 인터페이스 작성기에서 disabledControlTextColor로 색을 설정하면 잘 동작합니다. 선택하지 않으면 회색으로 표시되고 흰색으로 선택하면 프로그래밍 방식으로이 색을 특성 문자열 정의로 설정할 때 항상 표시됩니다. 회색.NSCell의 NSAttributedString

NSMutableAttributedString *result = [[[NSMutableAttributedString alloc] initWithString:value] autorelease]; 
NSDictionary *attributes = [[NSDictionary dictionaryWithObjectsAndKeys: 
            [NSFont systemFontOfSize:[NSFont systemFontSize] -1], NSFontAttributeName, 
            [NSColor disabledControlTextColor], NSForegroundColorAttributeName, nil] retain]; 

[result addAttributes:attributes range:[value rangeOfString:value]]; 

미리 감사드립니다.

답변

5

NSCell을 서브 클래스로 만들 때 텍스트 필드 값을 설정할 때 셀이 하이라이트되어 있는지 물어보고 텍스트의 전경색을 설정해야합니다. 사용자 정의 셀

NSString *titleValue = @"TEST"; 
NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:titleValue];  
NSColor *color = [self isHighlighted] ? [NSColor whiteColor] : [NSColor blackColor]; 
NSDictionary *attributes = [[NSDictionary dictionaryWithObjectsAndKeys: 
             [NSFont boldSystemFontOfSize:[NSFont systemFontSize] + 1], NSFontAttributeName, 
             color, NSForegroundColorAttributeName, nil] autorelease]; 
[titleString addAttributes:attributes range:[titleValue rangeOfString:titleValue]]; 
[self setAttributedStringValue:value]; 
0

사용이, 나는 인터넷에 모든 노력을 마지막 것은 아래는

- (void)updateCellDisplay { 
    if (self.selected || self.highlighted) { 
    self.nameLabel.textColor = [UIColor lightGrayColor]; 
    self.colorLabel.textColor = [UIColor lightGrayColor]; 
    } 
    else { 
    self.nameLabel.textColor = [UIColor blackColor]; 
    self.colorLabel.textColor = [UIColor blackColor]; 
    } 
} 

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 
    [super setHighlighted:highlighted animated:animated]; 
    [self updateCellDisplay]; 
} 

- (void) setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 
    [self updateCellDisplay]; 
} 
근무
관련 문제