2011-08-14 12 views
1

私のTableViewのセクションヘッダーの外観が変更されています。テキストをうまく動かすことができました。しかし、背景のイメージは全く現れていないようです。UITableView SectionHeaderがカスタム画像の背景を表示しない

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)] autorelease]; 
    UILabel *sectionTitle = [[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 30)] autorelease]; 
    sectionTitle.text = [[tableDataSource objectAtIndex: section] objectForKey: @"Title"]; 
    sectionTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:14]; 
    //sectionTitle.textColor = [UIColor whiteColor]; 
    sectionTitle.shadowColor = [UIColor colorWithWhite:0 alpha:0.4]; 
    sectionTitle.shadowOffset = CGSizeMake(1, 1); 
    sectionTitle.backgroundColor = [UIColor colorWithWhite:0 alpha:0]; 
    //headerView.backgroundColor = [UIColor whiteColor]; 

    UIImageView *sectionHeaderBG = [[UIImageView alloc] init]; 
    UIImage *image = [UIImage imageNamed:@"CellBackgroundGrey4.png"]; 
    sectionHeaderBG.image = image; 

    [headerView addSubview:sectionTitle];  
    [headerView addSubview:sectionHeaderBG]; 
    [headerView autorelease]; 
    return headerView; 
} 

紛失しているものがありますか?

答えて

4

はそれを試してみる:

headerView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"CellBackgroundGrey4.png"]]; 
+0

どうもありがとうございました。ニース行く:) – Andyy

2

UIImageViewframeを設定していなかったと思います。

+0

あなたはまた、右だった、ハハ、働い – Andyy

0
//custom sections 
- (NSString *)tableView:(UITableView *)tblView titleForHeaderInSection:(NSInteger)section { 

    NSString *sectionName = nil; 

    //set the table background to clear so you can see the background view behind it 
    tableView.backgroundColor = [UIColor clearColor]; 

    //where does this go? 

    UILabel *sectionHeader = [[UILabel alloc] init]; 
    sectionHeader.backgroundColor = [UIColor clearColor]; 
    sectionHeader.font = [UIFont boldSystemFontOfSize:18]; 
    sectionHeader.textColor = [UIColor whiteColor]; 

    //What is missing here? 

    switch (section) { 
     case 0: 
      sectionName = [NSString stringWithFormat:@"Header Text 1"]; 
      break; 
     case 1: 
      sectionName = [NSString stringWithFormat:@"Header Text 2"]; 
      break; 
     case 2: 
      sectionName = [NSString stringWithFormat:@"Header Text 3"]; 
      break; 
    } 

    return sectionName; 
関連する問題