更新:我最终使用了一个 nib 文件。有关如何为标题视图设置笔尖(文件 -> 新文件 -> 用户界面 -> 视图)的过程,请参阅 Josh Justice 的回答。这并不简单:已加载 nib 但未设置视图出口 - InterfaceBuilder 的新功能
我正在尝试UIView
在我的 Storyboard 中定义 a 并将其用作UITableView
标题的布局。我将此帖子用作指南,但似乎无法使其正常工作(ios7)。我试过使用UIImageView
如帖子中所示,以及常规UIView
但没有运气。我不明白的一件事是我可以创建一个新的UIView
,如下所示,并足够轻松地设置背景颜色,但是如果我使用标签从情节提要中加载视图,我似乎无法更改背景和它只显示为灰色。我在这里做错了什么?!我想我可以在代码中创建整个 Header 但似乎我在这里缺少一些东西。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// doing it this way, the header stays positioned
// and visible no matter where the table is scrolled
// UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
// pulling the view out of the storyboard doesn't seem to work
// can't change bgcolor on this view..
UIView *v = [[UIView alloc] viewWithTag:200];
// this only changes the background color when the view is created
// with initWithFrame.. above. Otherwise it's just gray.
[v setBackgroundColor:[UIColor colorWithRed:0 green:.7 blue:.9 alpha:1]];
return (v);
}