自定义IKImageBrowserView组外观 [英] customizing IKImageBrowserView group appearance

查看:110
本文介绍了自定义IKImageBrowserView组外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改IKImageBrowserView的组头的外观。
我已经看到我们可以提供带有IKImageBrowserGroupHeaderLayer的自定义CALayer,但是我根本不知道如何使用它(如何获取图层的大小,知道是否选择了该组,..)

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 not know at all how to use it (how to get the size of the layer, know if the group is selected, ....)

您对此有任何指针吗?

谢谢

推荐答案

我今天尝试了一下,它看起来相当简单。需要特别注意的是,它似乎仅适用于 IKImageGroupDisclosureStyle 组。

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.

这提供了一个不错的选择每组顶部的粉色线。看来,当视图显示该图层时,它会将图层的大小调整为浏览器视图的宽度,因此我在 width 中放置了 bounds 对结果没有影响,但确实符合高度

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];
}

关于知道是否选择了组,我假设您的意思是选择组中的哪些项目?我将观察视图的 selectionIndexes 进行更改,确定选择了哪个项目,然后确定它们属于哪个组(使用与提供<$ c相似的过程$ c> IKImageBrowserGroupRangeKey (在配置组时,我希望您已经缓存了!)并调用 reloadData ,其中一个组返回不同的图层配置(或其他方式)取决于它是否包含所选项目。

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.

这篇关于自定义IKImageBrowserView组外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆