customizing IKImageBrowserView group appearance

前端 未结 1 1430
天涯浪人
天涯浪人 2021-01-24 21:25

I am trying to change the appearance of the group header of an IKImageBrowserView. I\'ve seen that we can provide an custom CALayer with IKImageBrowserGroupHeaderLayer but I do

相关标签:
1条回答
  • 2021-01-24 22:13

    I have had a go at this today and it appeared reasonably straightforward. It was important to note, however, that it appears to only work with IKImageGroupDisclosureStyle groups.

    This provided a nice pink line along the top of each group. It seems that when the view displays the layer, it resizes the layer to the width of the browser view, so what I put in width for bounds made no difference to the result, however it does honour height.

    - (NSDictionary *) imageBrowser:(IKImageBrowserView *) aBrowser groupAtIndex:(NSUInteger) index
    {
        CALayer *headerLayer = [CALayer layer];
        headerLayer.bounds = CGRectMake(0.0, 0.0, 100.0, 30.0);
        CGColorRef colour = CGColorCreateGenericRGB(1.0, 0.5, 0.7, 1.0);
        headerLayer.backgroundColor = colour;
        CGColorRelease(colour);
    
        return [NSDictionary dictionaryWithObjectsAndKeys:
            [NSNumber numberWithInt: IKGroupDisclosureStyle], IKImageBrowserGroupStyleKey,
            headerLayer, IKImageBrowserGroupHeaderLayer,
        nil];
    }
    

    Regarding "know if the group is selected", I assume you mean if one of the items within the group is selected? I would observe the view's selectionIndexes for changes, determining which item or items were selected, then determining in which group they fall (using a similar process to how you provided the IKImageBrowserGroupRangeKey when configuring the group, which I hope you have cached!) and calling reloadData with one of the groups returning a different layer configuration (or whatever) based on whether it contains a selected item or not.

    0 讨论(0)
提交回复
热议问题