UPDATE: I ended up doing it with a nib file. See Josh Justice's answer here on how to go about the process of setting up the nib (File -> New File -> User Interface -> View) for a header view. It's not straightforward: Loaded nib but the view outlet was not set - new to InterfaceBuilder
I'm trying to define a UIView
in my Storyboard and use it as a layout for my UITableView
header. I used this post as a guide, but can't seem to get it working (ios7). I've tried using UIImageView
as shown in the post, as well as a regular UIView
but no luck. One thing I don't understand is that I can create a new UIView
, like below, and set the background color easily enough, but if I load the view out of the storyboard using the tag, I can't seem to change the background and it only shows up gray. What am I doing wrong here?! I guess I can create the entire Header in code but it seems like there is something I'm missing here.
- (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);
}