too*_*fah 19 iphone uitableview uikit
好的,我知道之前有人问过,所以请原谅我再问一次.看起来似乎必须有一种更简单的方法来做到这一点.
是否有一种"简单"的方式来更改UITableView部分标题背景颜色?我知道我可以使用委托方法'viewForHeaderInSection'来传递UITableView自定义UIView用于节标题,但我真正想做的就是设置'tintColor'.搜索栏上有一个tintColor属性,为什么不用于节标题.
如果我使用viewForHeaderInSection来创建我自己的自定义UIView,我也必须创建自己的标签.我必须将标签的样式和位置看起来与Apple标准的其他部分一样.我必须将"背景"的样式和大小看作是Apple标准的其余部分.
我找不到简单地询问节标题然后改变它的颜色的方法.我错过了什么,或者我真的必须这么做.
如果我必须这么做,那么有人拥有与Apple标准相匹配的所有样式信息吗? - 酒吧是'半透明' - 酒吧顶部和底部有一些阴影 - 标签有一定的大小,位置,阴影等
谢谢.再次,抱歉再次提出这个问题.
Mas*_*iti 30
使用更新的UIAppearance服务方式,在版本> iOS 6.0中,您可以这样做,例如:
[[UITableViewHeaderFooterView appearance] setTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)
Sok*_*lov 20
使用UIAppearance,您可以更改标题UILabel上的文字颜色,UITableView如下所示:
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setTextColor:[UIColor whiteColor]];
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setShadowColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
应该适用于iOS 6.0+.可以在任何地方调用(viewDidLoad等).
nei*_*ett 12
这是我花了很长时间与自己搏斗的事情,却发现没有办法只改变节头的tintColor.我想出的解决方案是截取节标题的背景,在Photoshop中更改它的色调,然后将其用作节标题的背景.然后它只是一个布局标签的案例.
正如您所说,使用的是viewForHeaderInSection委托方法.
这是我发现的工作,看起来像Apple默认:
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;
Run Code Online (Sandbox Code Playgroud)
这里"headerbackground.png"是1像素乘22像素(iPhone 4的两倍)图像,它将在标题的长度上重复出现.
希望这可以帮助!
如果您更改外观,就像在其他答案中一样,它是应用程序范围的.如果您只想更改特定的tableview,请执行:
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
UITableViewHeaderFooterView * headerview = (UITableViewHeaderFooterView *)view;
headerview.contentView.backgroundColor = [UIColor greenColor];
headerview.textLabel.textColor = [UIColor whiteColor];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14448 次 |
| 最近记录: |