在UITableView中的标题标题旁边添加图像

问题描述:

我已经使用Group-style创建了UITableView。我的桌子上只有一个组。在UITableView中的标题标题旁边添加图像

这里是我的两个问题:

1)如何在头球顶我旁边的标题显示的图片?基本上我想把我们公司的标志放在那个标题旁边。

2)我可以更改标题中的背景颜色(我不喜欢灰色)吗?我可以调整标题的高度吗?

只返回一个自定义视图您的标题是这样的:

//Draws a custom view for the header instructions 
-(UIView*)tableView:(UITableView*) tableView viewForHeaderInSection:(NSInteger)section; 
{ 
    if ([tableView numberOfRowsInSection:section] != 0) // To handle nil entries 
    { 
    UIView* headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 60)] autorelease]; 

     // set up whatever view you want here. E.g. 

    UILabel* headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, headerView.frame.size.width - 20.0, headerView.frame.size.height)]; 

     headerLabel.text = @"Tap items in the list to pin them.\nTap the Remix button to clear all unpinned items"; 
     headerLabel.numberOfLines = 0; 

    headerLabel.font = [UIFont fontWithName:@"HelveticaNeueLTStd-Lt" size: 14]; 
    headerLabel.backgroundColor = [UIColor clearColor]; 
    headerLabel.textColor = [UIColor colorWithRed:kColorRed green:kColorGreen blue:kColorBlue alpha:1]; 
    headerLabel.userInteractionEnabled = NO; 
     headerLabel.textAlignment = UITextAlignmentCenter; 

    headerView.backgroundColor = [UIColor clearColor]; 

    [headerView setTag:010]; 
    [headerView setAlpha:1]; 

    [headerView addSubview:headerLabel]; 
    [headerLabel release]; 
    return headerView; 
    } 
    else { 
     return nil; // again to handle nil tables. You should be nice and at least show an error label on the view. 
    }  
} 

这给了你这样的:

How it should only work

+0

非常感谢您的帮助。我确实实施了这个方法,但是我的程序崩溃了。我正在使用ARC,因此我删除了所有的自动重新发布 – xcoderookie 2012-02-21 22:29:55

+0

唉,希望它以后能够正常工作。如果您发现问题的解决方案,请确保勾选复选标记! – rinzler 2012-02-26 03:07:50