0

我正在制作一个 iPhone 应用程序。在这个应用程序中,我有一个 UITableView,它有一个 UITableView 标题。这就是我的代码的样子。

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 308, 50)];
    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sx_home_tablehead.png"]];
    self.tableViewAppointments.tableHeaderView = view;

这就是我的 iPhone 上的样子

在此处输入图像描述 这就是我想要实现的

在此处输入图像描述

希望任何人都可以帮助我!

亲切的问候 !

4

2 回答 2

0

如果要将其添加为表格视图节标题,则需要按如下方式添加,

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

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 308, 50)];
    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sx_home_tablehead.png"]];
 //or,
    UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sx_home_tablehead.png"]];
    return view;
}

您可以在中定义标题的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return height;
}
于 2012-11-28T18:48:47.227 回答
0

因为您明确指定了视图的框架。你不应该做这样可怕的黑客攻击。请改用这段代码:

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header.png"]];
self.tableView.tableHeaderView = imgView;
于 2012-11-28T18:48:49.067 回答