如何将图像和标题添加到表视图的标题IOS

问题描述:

在表视图中,我创建了标题。如何将图像和标题添加到表视图的标题IOS

什么是在tableView的头设置图像或标题的正确方法?我需要做什么?

TIA

+0

你指的是在的tableView或公共首标段的标头,TableView中 – tGilani 2012-08-06 07:03:04

+0

头的顶部只有部分。 – Feroz 2012-08-06 07:09:48

在该方法中

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 

你需要创建一个UIView并添加其他视图一样UIImageView(图像),UILabel(为标题),最后返回UIView

+0

图片现在正在添加,但其扩展为完整标题,我们是否需要设置高度和宽度? – Feroz 2012-08-06 07:13:58

+1

创建您的UIImageView时,请使用您的需求矩阵进行初始化。例如 ** UIImageView * imgView = [UIImageView alloc] initWithFrame:CGRectMake(CGFloat x,CGFloat y,CGFloat width,CGFloat height)]; ** – Neo 2012-08-06 07:16:45

+0

雅谢谢我做过。 :) – Feroz 2012-08-06 07:24:39

- (UIView *)tableView : (UITableView *)tableView viewForHeaderInSection : (NSInteger) section { 

    UIImageView *imgVew = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]]; 
    return imgVew; 
} 

通过这个,你可以设置图片为背景的tableview节头!

请使用此代码:

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

} 
+0

不适合我。 100pt的高度不适用 – 2013-06-05 10:09:34

我用这个代码:

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.tableView.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]]; 
} 
+0

由于某种原因,我无法完成他的工作 – Shailesh 2015-12-27 15:12:59

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


}