2013-03-07 2 views
0

표준 IKImageBrowserCell 강조 표시 크기의 크기를 조정하고 싶습니다. 나는 비슷한 질문을 stackoverflow here (링크에서 당신은 표준 IKImageBrowserCell 선택 하이라이트를 볼 수 있습니다) 발견.ImageBrowserCell 강조 치수 변경

IKImageBrowserCell 및 하이라이트 차원을 완전히 사용자 정의하는 사과 샘플 코드를 찾았습니다. 이러한 프레임

- (NSRect) imageFrame 
{ 
// //get default imageFrame and aspect ratio 
    NSRect imageFrame = [super imageFrame]; 

    if(imageFrame.size.height == 0 || imageFrame.size.width == 0) return NSZeroRect; 

    float aspectRatio = imageFrame.size.width/imageFrame.size.height; 

    // compute the rectangle included in container with a margin of at least 10 pixel at the bottom, 5 pixel at the top and keep a correct aspect ratio 
    NSRect container = [self imageContainerFrame]; 
    container = NSInsetRect(container, 8, 8); 

    if(container.size.height <= 0) return NSZeroRect; 

    float containerAspectRatio = container.size.width/container.size.height; 

    if(containerAspectRatio > aspectRatio){ 
     imageFrame.size.height = container.size.height; 
     imageFrame.origin.y = container.origin.y; 
     imageFrame.size.width = imageFrame.size.height * aspectRatio; 
     imageFrame.origin.x = container.origin.x + (container.size.width - imageFrame.size.width)*0.5; 
    } 
    else{ 
     imageFrame.size.width = container.size.width; 
     imageFrame.origin.x = container.origin.x;  
     imageFrame.size.height = imageFrame.size.width/aspectRatio; 
     imageFrame.origin.y = container.origin.y + container.size.height - imageFrame.size.height; 
    } 

    //round it 
    imageFrame.origin.x = floorf(imageFrame.origin.x); 
    imageFrame.origin.y = floorf(imageFrame.origin.y); 
    imageFrame.size.width = ceilf(imageFrame.size.width); 
    imageFrame.size.height = ceilf(imageFrame.size.height); 

    return imageFrame; 
} 

//--------------------------------------------------------------------------------- 
// imageContainerFrame 
// 
// override the default image container frame 
//--------------------------------------------------------------------------------- 
- (NSRect) imageContainerFrame 
{ 
    NSRect container = [super frame]; 

    //make the image container 15 pixels up 
    container.origin.y += 15; 
    container.size.height -= 15; 

    return container; 
} 

설정된 두 개의 겹쳐 쓸 방법이며, 이는의 문제는 그 코드의 결과는 선택 강조 표시

/* selection layer */ 
if(type == IKImageBrowserCellSelectionLayer){ 

    //create a selection layer 
    CALayer *selectionLayer = [CALayer layer]; 

    selectionLayer.frame = CGRectMake(0, 0, frame.size.height, frame.size.height); 

    float fillComponents[4] = {1.0, 0, 0.5, 0.3}; 
    float strokeComponents[4] = {1.0, 0.0, 0.5, 1}; 

    //set a background color 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    color = CGColorCreate(colorSpace, fillComponents); 
    [selectionLayer setBackgroundColor:color]; 
    CFRelease(color); 

    //set a border color 
    color = CGColorCreate(colorSpace, strokeComponents); 
    [selectionLayer setBorderColor:color]; 
    CFRelease(color); 

    [selectionLayer setBorderWidth:2.0]; 
    [selectionLayer setCornerRadius:5]; 

    return selectionLayer; 
} 

를 생성하는 코드이다

enter image description here

프레임을 볼 수 있듯이 선택 영역의 프레임이 변경되었지만 수정할 수는 없습니다. 간단히 강조 표시를 이미지 축소판과 동일한 크기로 만들고 싶습니다. 선택 코드 (selectionLayer.frame = CGRectMake(0, 0, frame.size.height, frame.size.height);)를 수정하려고했지만 아무 일도 일어나지 않습니다. 누구든지 나를 도울 수 있습니까? 감사! 당신이 IKImageBrowserCell의 커스텀 레이아웃하려면 사용자 정의 선택 프레임 레이아웃에

답변

0

, 당신은 여기에 -[IKImageBrowserCell selectionFrame]


를 오버라이드 (override) 재정의 할 수있는 방법이 있습니다해야합니다. 당신이

- (CGFloat) opacity; 
- (CALayer *) layerForType:(NSString *) type; 
IKImageBrowserCell

의 커스텀 모습 원하는 경우 여기
- (NSRect) imageContainerFrame; 
- (NSRect) imageFrame; 
- (NSRect) selectionFrame; 
- (NSRect) titleFrame; 
- (NSRect) subtitleFrame; 
- (NSImageAlignment) imageAlignment; 

는 오버라이드 (override) 할 수있는 방법이 있습니다