iphone - 添加 iOS UITableView HeaderView(不是部分标题)

标签 iphone ios uitableview

我想添加一个表格标题(不是部分标题),例如在联系人应用程序中: enter image description here

完全一样 - 表格上方图像旁边的标签。

我希望所有 View 都可以滚动,这样我就不能将它们放在表格之外。

我该怎么做?

最佳答案

UITableView 有一个 tableHeaderView 属性。将其设置为您想要的任何 View 。

使用一个新的 UIView 作为容器,向新的 UIView 添加一个文本标签和一个 ImageView ,然后将 tableHeaderView 设置为新观点。

例如,在 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];
     // ...
} 

关于iphone - 添加 iOS UITableView HeaderView(不是部分标题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5441938/

相关文章:

ios - 如何将 CAGradientLayer 添加到 CAShapeLayer?

在 id 的对象上找不到 iOS SpringBoard 属性 badgeNumberOrString

ios - UITableViewAutomaticDimension 不适用于 iOS8 中的页脚

ios - 重新定位 UITableView

iphone - 如何避免 iOS (MVC) 中同一模型对象的多个实例

ios - iPhone 应用编程 : best element from the interface builder to display calculated values

ios - “Static member ' … ' cannot be used on instance of type ' … '”

ios - 在自定义 UITableViewHeaderFooterView 上添加一个按钮

iphone - 如何在从 URL 流式传输音频时全屏显示 MPMoviePlayerController 的事件指示器

iphone - UIWebView 支持的文件格式