现在的位置: 首页 > 综合 > 正文

如何自定义UITableView标题

2013年09月10日 ⁄ 综合 ⁄ 共 1356字 ⁄ 字号 评论关闭


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

    UIView *v_headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 23)];//创建一个视图(v_headerView

    UIImageView *v_headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320,23)];//创建一个UIimageViewv_headerImageView

    v_headerImageView.image = [UIImage imageNamed:@"ip_top
bar.png"
];//v_headerImageView设置图片

    [v_headerView addSubview:v_headerImageView];//v_headerImageView添加到创建的视图(v_headerView)中

    [v_headerImageView release];//释放v_headerImageView所占用的资源

    UILabel *v_headerLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 1, 100, 19)];//创建一个UILablev_headerLab)用来显示标题

    v_headerLab.backgroundColor = [UIColor clearColor];//设置v_headerLab的背景颜色

    v_headerLab.textColor = [UIColor grayColor];//设置v_headerLab的字体颜色

    v_headerLab.font = [UIFont fontWithName:@"Arial" size:13];//设置v_headerLab的字体样式和大小

    v_headerLab.shadowColor = [UIColor whiteColor];//设置v_headerLab的字体的投影

    [v_headerLab setShadowOffset:CGSizeMake(0, 1)];//设置v_headerLab的字体投影的位置

    //设置每组的的标题

    if (section == 0) {

        v_headerLab.text = @"拍品导航";

    }

    if (section == 1) {

        v_headerLab.text = @"专场特卖";

    }

    [v_headerView addSubview:v_headerLab];//将标题v_headerLab添加到创建的视图(v_headerView)中

    [v_headerLab release];//释放v_headerLab所占用的资源

    return v_headerView;//将视图(v_headerView)返回

}

【上篇】
【下篇】

抱歉!评论已关闭.