自定义 IKImageBrowserView 组外观

发布于 2024-12-18 06:38:10 字数 162 浏览 3 评论 0原文

我正在尝试更改 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, ....)

Do you have any pointer for this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2024-12-25 06:38:10

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

这在每组的顶部提供了一条漂亮的粉红色线。看来,当视图显示图层时,它会将图层大小调整为浏览器视图的宽度,因此我在 bounds 中输入的 width 对结果没有任何影响,但是它确实尊重高度

- (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 的变化,确定选择了哪个或哪些项目,然后确定它们属于哪个组(使用与在以下情况下提供 IKImageBrowserGroupRangeKey 类似的过程)配置组,我希望您已缓存!)并调用 reloadData ,其中一个组根据是否包含所选项目返回不同的图层配置(或其他内容)。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文