更改UITableView节标题的颜色 [英] Changing the color of UITableView section headers

查看:90
本文介绍了更改UITableView节标题的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我知道之前有人问过,所以请原谅我再问一次。似乎必须有一个更简单的方法来做到这一点。

OK, I know that this has been asked previously, so please forgive me for asking again. It just seems like there has got to be an easier way to do this.

是否有一种简单的方式来更改UITableView部分标题背景颜色?我知道我可以使用委托方法'viewForHeaderInSection'来传递UITableView自定义UIView用于节标题,但我真正想做的就是设置'tintColor'。搜索栏上有一个tintColor属性,为什么不用于节标题。

Is there a 'simple' way to change the UITableView section header background color? I know that I can use the delegate method 'viewForHeaderInSection' to hand the UITableView a custom UIView to use for the section headers, but all I really want to do is set the 'tintColor'. There is a tintColor property on the search bar, why not for the section headers.

如果我使用viewForHeaderInSection创建我自己的自定义UIView,我必须创建自己的标签同样。我必须将标签的样式和位置看起来与Apple标准的其他部分一样。我必须将'背景'的样式和大小看作是Apple标准的其余部分。

If I use viewForHeaderInSection to create my own custom UIView, I have to create my own label as well. I have to style and position my label to look just like the rest of the Apple standard. I have to style and size the 'background' to look like the rest of the Apple standard.

我找不到简单地询问节标题的方法然后改变它的颜色。我是否遗漏了某些东西,或者我真的必须这么做。

I can't find a way to simply ask for the section header and then change it's color. Am I missing something or do I really have to do this the hard way.

如果我必须这么做,那么有人拥有所有的造型信息吗符合Apple标准?
- 酒吧是'半透明'
- 酒吧顶部有一些阴影,底部有
- 标签有一定的尺寸,位置,阴影等等

If I have to do this the hard way, does someone have all of the styling information that matches the Apple standard? - bar is 'translucent' - bar has some shading on the top and the bottom - label has a certain size, position, shadings, etc

谢谢。再次,抱歉再次提出这个问题。

Thanks. And once again, sorry for asking this question again.

推荐答案

这是我花了很长时间与自己搏斗的事情,只是为了发现没有办法只改变节头的tintColor。我想出的解决方案是截取节标题的背景,在Photoshop中更改它的色调,然后将其用作节标题的背景。然后它只是一个布局标签的情况。

This is something I spent quite a while grappling with myself, only to find that there is no way to just change the tintColor of the section header. The solution I came up with was to screenshot the background of the section header, change the tint of it in Photoshop, and then use that as the background of the section header. Then its just a case of laying out the label.

如你所说,要使用的是viewForHeaderInSection委托方法。

As you said, the thing to use is the viewForHeaderInSection delegate method.

这是我发现的工作,看起来像Apple默认:

Here is what I've found works and looks like the Apple default:

UIView *customView = [[[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 320.0, 22.0)] autorelease];
customView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"headerbackground.png"]];;

UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
headerLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
headerLabel.frame = CGRectMake(11,-11, 320.0, 44.0);
headerLabel.textAlignment = UITextAlignmentLeft;
headerLabel.text = @"Header Label";
[customView addSubview:headerLabel];
return customView;

这里headerbackground.png是1像素乘22像素(iPhone 4的两倍)图像这将在标题的长度上重复。

Here "headerbackground.png" is a 1 pixel by 22 pixel (double that for iPhone 4) image that will get repeated across the length of the header.

希望这有帮助!

这篇关于更改UITableView节标题的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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