各部分左侧的UITableView标题(如Spotlight) [英] UITableView headers on the left side of sections (like Spotlight)

查看:112
本文介绍了各部分左侧的UITableView标题(如Spotlight)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经搜索了很长一段时间了,我仍然没有办法做到这一点。
我想将iPhone Spotlight的部分标题重现为UITableView。

Been searching for this for quite a while, and I still haven't found a way to do it. I'd like to reproduce the section headers of the iPhone's Spotlight into a UITableView.

常规表格视图标题在部分顶部保持可见当你滚动时,我们都知道。但是有一种标题,我在其他地方从未见过,而不是在Springboard的Spotlight页面中:标题跨越整个部分的高度并且没有卡在部分的顶部,而是在左侧。

"Regular" table view headers stay visible at the top of a section when you scroll, as we all know. But there is one kind of header that I've never seen elsewhere than in the Spotlight page of Springboard: there, the headers span the whole height of the section and are not stuck on the top of the section, but on the left side.

这是怎么回事?

推荐答案

好问题。我做了一个小实验。它几乎看起来像聚光灯下的景色。但它缺乏一个导入功能。如果它们发生碰撞,较低的图像不会将上部图像推到顶部。

Good question. I made a little experiment. It almost looks like the view from spotlight. But it's lacking one import feature. The lower "image" doesn't push the upper image to the top if they collide.

我怀疑有没有使用私有框架的内置解决方案。

I doubt that there is a built in solution without the use of private frameworks.

我实现了这个目标:

正如您可以看到顶部的两个标题图像重叠。它们不像普通标题那样互相推动。我不得不停用细胞分离器。如果我会使用它们,它们会出现在整个细胞中。所以你必须自己画画。没什么大不了的。

As you can see the two header images at the top overlap. They don't push each other like normal headers to. And I had to deactivate the cell separators. If I would use them they would appear at the whole cell. So you have to draw them yourself. Not a big deal.

但我不知道如何解决重叠问题。

But I have no idea how I could fix the overlapping.

以下是实现此目的的代码:

Here is the code that made this happen:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 44)];
    contentView.backgroundColor = [UIColor lightGrayColor];

    UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 34, 34)] autorelease];
    imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d", section]];;

    [contentView addSubview:imageView];
    return [contentView autorelease];
}

这篇关于各部分左侧的UITableView标题(如Spotlight)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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