Default section head title font & color and so on

参考:

[1]http://stackoverflow.com/questions/5869344/uitableview-header-footer-font-color

[2]http://www.iphonedevsdk.com/forum/iphone-sdk-development/1199-default-tableview-section-header-background-color.html

UITableview可以由多个Section组成,每个section可以由若干个row,并且可以为section设置title标题,可以用来设置标题。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different
这是个UITableViewDataSource的回调函数,当显示完成后,除非你roloadData,而roloadData会带来性能花费, 否则不会重新调用。因此,你也不能对实时的改变title。

这时可以通过返回一个view给Section head,这样你就可以addsubview显示任何你想显示的,并且将此view做为实例成员,就可以做到实时改变,而不需要reloadData。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;   // custom view for header. will be adjusted to default or specified header height

但有个问题,你如何使显示的section 标题,跟通过titleForHeaderInSection回调显示的一样,就是你不清楚它所用的字体、颜色、等等信息。所以要想显示的跟系统一样就需要以下信息

Plain
fontName: Helvetica-Bold
pointSize: 18.000000
textColor: UIDeviceWhiteColorSpace 1 1
shadowColor: UIDeviceWhiteColorSpace 0 0.44
shadowOffset: CGSize 0 1


Grouped
fontName: Helvetica-Bold
pointSize: 17.000000
textColor: UIDeviceRGBColorSpace 0.298039 0.337255 0.423529 1
shadowColor: UIDeviceWhiteColorSpace 1 1
shadowOffset: CGSize 0 1


我用到的相关代码如下:

	UILabel* sectionHeadLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 320, 44)];
	sectionHeadLabel.backgroundColor = [UIColor clearColor];
	sectionHeadLabel.textColor    = [UIColor colorWithRed:0.298039 green:0.337255 blue:0.423529 alpha:1.0];
    sectionHeadLabel.shadowColor  = [UIColor colorWithWhite:1.0 alpha:1.0];
	sectionHeadLabel.shadowOffset = CGSizeMake(0, 1); 
	sectionHeadLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.0f];




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值