Changing the color of UITableView section headers(更改 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 部分标题的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更改 UITableView 部分标题的颜色
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01