How to customize IKImageBrowserView to add a NSButton on each item?

独自空忆成欢 提交于 2019-12-02 01:48:44

You're headed in the right direction. You need to check the type and add the buttons to the Foreground layer. Here's some code from an existing project of mine.

- (CALayer *)layerForType:(NSString *)type
{
    if (type == IKImageBrowserCellBackgroundLayer) {
        CALayer *layer = [CALayer layer];
        NSRect rect = [self frame];
        layer.frame = rect;
        _frameBg = rect;
        CGFloat cellSize = rect.size.height;

        SSLayerBackground *bgLayer = [SSLayerBackground layer];
        [layer addSublayer:bgLayer];
        [bgLayer setFrame:rect];
        bgLayer.position = NSMakePoint(rect.size.width/2.0, rect.size.height/2.0);
        [bgLayer setNeedsDisplay];

        /* Create background layer here */

        return layer;
    } else if (type == IKImageBrowserCellForegroundLayer) {
        CALayer *layer = [CALayer layer];
        NSRect rect = [self frame];
        layer.frame = rect;
        CGFloat cellSize = rect.size.width;


        /* Add your buttons to this layer */

        return layer;
    } else if (type == IKImageBrowserCellSelectionLayer) {
        CALayer *layer = [CALayer layer];
        NSRect rect = [self frame];
        layer.frame = rect;
        CGFloat cellSize = rect.size.height;

        /* Do selection layer stuff here */

        return layer;
    }
    //return nil;
    return [super layerForType:type];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!