2012-08-06 107 views

回答

3

在该方法中

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

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

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

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

0

请使用此代码:

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

1

我用这个代码:

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

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

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


} 
相关问题