自定义UITableView标题部分 [英] Customize UITableView header section

查看:121
本文介绍了自定义UITableView标题部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为每个部分自定义 UITableView 标头。到目前为止,我已经实现了

I want to customize UITableView header for each section. So far, I've implemented

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

UITabelViewDelegate 方法。我想要做的是获取每个部分的当前标题,并添加 UILabel 作为子视图。

this UITabelViewDelegate method. What I want to do is to get current header for each section and just add UILabel as a subview.

到目前为止,我无法做到这一点。因为,我找不到任何东西来获取默认节标题。第一个问题,有没有办法获得默认部分标题

So far, I'm not able to accomplish that. Because, I couldn't find anything to get default section header. First question,is there any way to get default section header ?

如果不可能,我需要创建一个容器视图,这是一个 UIView 但是,这次我需要设置默认的背景颜色,阴影颜色等。因为,如果你仔细查看部分的标题,它已经被自定义了。

If it's not possible, I need to create a container view which is a UIView but,this time I need to set default background color,shadow color etc. Because, if you look carefully into section's header, it's already customized.

如何为每个部分标题获取这些默认值?

How can I get these default values for each section header ?

谢谢大家。

推荐答案

你可以试试这个:

 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
    /* Create custom view to display section header... */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
    [label setFont:[UIFont boldSystemFontOfSize:12]];
     NSString *string =[list objectAtIndex:section];
    /* Section header is in 0th index... */
    [label setText:string];
    [view addSubview:label];
    [view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
    return view;
}

这篇关于自定义UITableView标题部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆