views:

258

answers:

2

I have a tableview where I am displaying a list of data. I would like to have a logo instead of just text for the header portion of the view. The code below gives me just the text.

Any ideas on how to get the image in there?

  • (void)viewDidLoad { [super viewDidLoad]; self. = @"Videos";
A: 

Something like that:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 69.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* headerView = [[UIView alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 69.0)];
    headerView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"header1" ofType: @"png"]]];
    return headerView;
}
sha
This will put the image on the header of every section, not the table header.
benzado
+2  A: 

To get an icon in the navigation bar (basically what the Facebook app does) use the navigationItem's titleView property. You can put an arbitrary UIView there, and a UIImageView with the logo on a transparent background would give the same effect that Facebook uses. Do this in viewDidLoad and you're set.

Any view controller can use a UINavigationItem, so if you're not using a navigation controller you should still be able to get one.

Alternately, just add a UIToolbar wherever it makes sense, and give it a UIBarButtonItem with a custom view set to a UIImageView.

Tom Harrington