添加 iOS UITableView HeaderView(不是部分标题) [英] Adding iOS UITableView HeaderView (not section header)
问题描述
我想在联系人应用程序中添加一个表格标题(不是节标题),例如:
I want to add a table header (not section headers) like in the contacts app for example:
正是如此 - 表格上方图像旁边的标签.
exactly like that - a label beside an image above of the table.
我希望所有视图都是可滚动的,所以我不能将它们放在表格之外.
I want the all view be scrollable so I can't place those outside of the table.
我该怎么做?
推荐答案
UITableView
有一个 tableHeaderView
属性.将其设置为您想要的任何视图.
UITableView
has a tableHeaderView
property. Set that to whatever view you want up there.
使用新的 UIView
作为容器,向新的 UIView
添加文本标签和图像视图,然后将 tableHeaderView
设置为新视图.
Use a new UIView
as a container, add a text label and an image view to that new UIView
, then set tableHeaderView
to the new view.
例如,在 UITableViewController
中:
-(void)viewDidLoad
{
// ...
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:imageView];
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:labelView];
self.tableView.tableHeaderView = headerView;
[imageView release];
[labelView release];
[headerView release];
// ...
}
这篇关于添加 iOS UITableView HeaderView(不是部分标题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!