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

查看:13
本文介绍了更改 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.

推荐答案

这个问题我自己纠结了好久,才发现没有办法只改变section header的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 像素 x 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天全站免登陆