2012-08-06 195 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; 


}