2011-02-18 8 views
2

나는 내가,NSOutlineView 변경 그룹 행 색상

이 이렇게하려면 NSTextFieldCell에서 서브 클래스입니다 정의 셀, I는 그룹 행과 그 선택 일반 행에 대해 서로 다른 색상을 그릴 필요 을 사용하고 있습니다

-(id)_highlightColorForCell:(NSCell *)cell 
{ 
    return [NSColor colorWithCalibratedWhite:0.5f alpha:0.7f]; 
} 

그래 내가 그 개인 API를 알고,하지만 난이 정상 행에 대해 매우 잘 작동 다른 방법으로, 하지만 그룹 행에 영향을 찾을 수 없었다, 다음과 같은 짓을, 어떤 방식이 있나요 그룹 색상 변경,

친절하게 반갑습니다 로한

답변

3

적어도 Mac OS X 10.4 이상을 요구하시는 경우 비공개 API에 의존하지 않고이 작업을 수행 할 수 있습니다.

는 휴대 서브 클래스에 다음을 넣어 :

- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{ 
    // Returning nil circumvents the standard row highlighting. 
    return nil; 
} 

을 그리고 다음 NSOutlineView를 서브 클래스와 메소드를 다시 구현, - (무효) highlightSelectionInClipRect : (NSRect)의 clipRect; 여기

은 하나 개의 비 그룹 행에 대한 색상과 다른

- (void)highlightSelectionInClipRect:(NSRect)clipRect 
{ 
    NSIndexSet *selectedRowIndexes = [self selectedRowIndexes]; 
    NSRange visibleRows = [self rowsInRect:clipRect]; 

    NSUInteger selectedRow = [selectedRowIndexes firstIndex]; 
    while (selectedRow != NSNotFound) 
    { 
    if (selectedRow == -1 || !NSLocationInRange(selectedRow, visibleRows)) 
    { 
     selectedRow = [selectedRowIndexes indexGreaterThanIndex:selectedRow]; 
     continue; 
    } 

    // determine if this is a group row or not 
    id delegate = [self delegate]; 
    BOOL isGroupRow = NO; 
    if ([delegate respondsToSelector:@selector(outlineView:isGroupItem:)]) 
    { 
     id item = [self itemAtRow:selectedRow]; 
     isGroupRow = [delegate outlineView:self isGroupItem:item]; 
    } 

    if (isGroupRow) 
    { 
     [[NSColor alternateSelectedControlColor] set]; 
    } else { 
     [[NSColor secondarySelectedControlColor] set]; 
    } 

    NSRectFill([self rectOfRow:selectedRow]); 
    selectedRow = [selectedRowIndexes indexGreaterThanIndex:selectedRow]; 
    } 
} 
+0

@thanks의 cayden, 난이 밖으로 시도 할 것이다, 의도적으로 개인 API를 사용하지 않은 그룹 행에 대한을 그립니다 예를 들어,하지만 싶었어요 한 가지만 알면 그룹 행 색상을 어떻게 바꿀 수 있습니까? – Amitg2k12

+1

위의 경우 그룹 행 색상을 선택하면 변경할 수 있습니다. 다른 행의 행 배경색을 변경하려면 drawRow : clipRect : 메서드를 재정의하십시오. – Cayden

+0

감사합니다. 시도해 봅시다. – Amitg2k12