开发者

How can I add an image into a tableview "header"?

开发者 https://www.devze.com 2022-12-21 14:01 出处:网络
I have a UITableView 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.

I have a UITableView 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 
{
 开发者_如何学Go   [super viewDidLoad];
    self. = @"Videos";


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;
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号