我几乎可以肯定你不能轻松地做到这一点。最近,我在我的开发帐户上使用了一次技术支持请求,询问如何修改UITableView部分的背景和边框。苹果工程师告诉我,这确实不是一件容易的事情,即使你设法做到了,也可能会影响性能。他还指向了cocoawithlove网站上一篇关于编辑uitableviews的文章:
http://cocoawithlove.com/2009/08/adding-shadow-effects-to-uitableview.html
实际上,创建自己的标题并不需要太多的工作。下面是我从我的一个项目中提取的一些代码 - 它被注释掉了,所以可能不能直接使用 - 但你可以得到一个想法:
- (CAGradientLayer *) greyGradient {
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.startPoint = CGPointMake(0.5, 0.0);
gradient.endPoint = CGPointMake(0.5, 1.0);
UIColor *color1 = [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1.0];
UIColor *color2 = [UIColor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:240.0f/255.0f alpha:1.0];
[gradient setColors:[NSArray arrayWithObjects:(id)color1.CGColor, (id)color2.CGColor, nil]];
return gradient;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
CGFloat width = CGRectGetWidth(tableView.bounds);
CGFloat height = [self tableView:tableView heightForHeaderInSection:section];
UIView *container = [[[UIView alloc] initWithFrame:CGRectMake(0,0,width,height)] autorelease];
container.layer.borderColor = [UIColor grayColor].CGColor;
container.layer.borderWidth = 1.0f;
CAGradientLayer *gradient = [self greyGradient];
gradient.frame = container.bounds;
[container.layer addSublayer:gradient];
UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectMake(12,0,width,height)] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.font= [UIFont boldSystemFontOfSize:19.0f];
headerLabel.shadowOffset = CGSizeMake(1, 1);
headerLabel.textColor = [UIColor whiteColor];
headerLabel.shadowColor = [UIColor darkGrayColor];
NSString *title = [self tableView:tableView titleForHeaderInSection:section];
headerLabel.text = title;
return container;
}
确保
#import <QuartzCore/QuartzCore.h>
顺便说一下...这不是要模仿标准标题的外观 - 这只是一个例子。但我相信经过一些尝试和错误,您可以改变它以模仿标准标题,然后稍微改变颜色。