如何自定义表格视图的标题?

时间:2011-02-04 06:25:46

标签: iphone uitableview alignment customization title

在我的应用程序中,我需要在表格视图的每个标题中显示两个数据,如此

enter image description here

在左侧的那一天&在右侧,将显示日期。

这里的问题是,当天和由于字母的变化,日期未正确对齐。这一天应该左对齐,而日期应该是右对齐的。

我该怎么做才能得到这个?请简要说明一下

先谢谢

1 个答案:

答案 0 :(得分:0)

使用

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

创建自己的剖面视图的方法。我相信你需要做这样的事情:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *myView = [[[UIView alloc] init] autorelease];
    UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"name_of_bg_image.png"]];
    [myView addSubview:bgImage];
    [bgImage release];

    UILabel *lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(SomeFrameHere)];
...set label properties and text...
    [myView addSubview:lbl1];
    [lbl1 release];

... create 2nd label with alignment to the right border here...

    return myView;
}
相关问题