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.
我有一个tableview,我正在显示一个数据列表。我想为视图的标题部分添加徽标而不仅仅是文本。下面的代码只给出了文字。
Any ideas on how to get the image in there?
关于如何在那里获得图像的任何想法?
- (void)viewDidLoad { [super viewDidLoad]; self. = @"Videos";
(void)viewDidLoad {[super viewDidLoad];自。 = @“视频”;
2 个解决方案
#1
3
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.
要在导航栏中显示一个图标(基本上是Facebook应用程序所做的),请使用navigationItem的titleView属性。您可以在那里放置任意UIView,在透明背景上带有徽标的UIImageView将产生与Facebook使用相同的效果。在viewDidLoad中执行此操作并进行设置。
Any view controller can use a UINavigationItem, so if you're not using a navigation controller you should still be able to get one.
任何视图控制器都可以使用UINavigationItem,因此如果您不使用导航控制器,您仍然可以获得一个。
Alternately, just add a UIToolbar wherever it makes sense, and give it a UIBarButtonItem with a custom view set to a UIImageView.
或者,只需在任何有意义的地方添加UIToolbar,并为其提供一个UIBarButtonItem,其自定义视图设置为UIImageView。
#2
4
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;
}
#1
3
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.
要在导航栏中显示一个图标(基本上是Facebook应用程序所做的),请使用navigationItem的titleView属性。您可以在那里放置任意UIView,在透明背景上带有徽标的UIImageView将产生与Facebook使用相同的效果。在viewDidLoad中执行此操作并进行设置。
Any view controller can use a UINavigationItem, so if you're not using a navigation controller you should still be able to get one.
任何视图控制器都可以使用UINavigationItem,因此如果您不使用导航控制器,您仍然可以获得一个。
Alternately, just add a UIToolbar wherever it makes sense, and give it a UIBarButtonItem with a custom view set to a UIImageView.
或者,只需在任何有意义的地方添加UIToolbar,并为其提供一个UIBarButtonItem,其自定义视图设置为UIImageView。
#2
4
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;
}