带有自定义部分标题iOS的UITableview

时间:2014-08-18 06:39:45

标签: ios iphone uitableview

我有桌面视图,我想根据时间显示事件。假设我在下午3点有2个事件,那么我需要节标题 3 PM ,并且在那两行中包含事件标题。

enter image description here

在上面的虚拟图像中有2个部分(下午3:00和下午7:00)各自的事件。和表格标题是日期。

我已经在Table视图上工作但没有部分。请帮我实现这个目标。

1 个答案:

答案 0 :(得分:1)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return how many section you need
}

//设置节标题高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0f;
}

//设置剖面视图

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tblImageList.frame.size.width, 40)];
   [vw setBackgroundColor:[UIColor clearColor]];
   UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tblImageList.frame.size.width, 40)];
   [lbl setText:@"your text"];
   [lbl setBackgroundColor:[UIColor clearColor]];
   [lbl setTextColor:[UIColor colorWithRed:45.0f/255.0f green:206.0/255.0f blue:189.0f/255.0f alpha:1.0f]];
   [vw addSubview:lbl];

   return vw;

}