xcode 如何将图像和标题添加到表视图 IOS 的标题中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11823713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add image and title to header of table view IOS
提问by Feroz
In table view I have created header.
在表视图中,我创建了标题。
What is the correct way to set image or title in tableView's header? What I need to do?
在 tableView 的标题中设置图像或标题的正确方法是什么?我需要做什么?
TIA
TIA
回答by Nina
- (UIView *)tableView : (UITableView *)tableView viewForHeaderInSection : (NSInteger) section {
UIImageView *imgVew = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];
return imgVew;
}
By this you can set image background for tableview section header!
通过这个,您可以为 tableview 部分标题设置图像背景!
回答by Neo
In the method
在方法中
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
you need to create a UIView
and add other views like UIImageView
(for image), UILabel
(for title) and return the UIView
at last.
您需要创建一个UIView
并添加其他视图,例如UIImageView
(用于图像)、UILabel
(用于标题)并UIView
最后返回。
回答by carmen_munich
I used this code:
我使用了这个代码:
-(void)viewDidLoad
{
[super viewDidLoad];
self.tableView.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];
}
回答by Prathyush Kommisetty
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImage * image = [UIImage imageNamed:@"logo-big.png"];
UIImageView * imgview = [[UIImageView alloc]initWithImage:image];
imgview.frame = CGRectMake(0, 0, 200, 200);
imgview.backgroundColor = [UIColor blackColor];
return imgview;
}
回答by Hemant Dixit
Please use this code:
请使用此代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImage *myImage = [UIImage imageNamed:@"loginHeader.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,300,100);
return imageView;
}