更改的TableView标题文字颜色(Change TableView Header Text Co

2019-10-16 22:21发布

我想对我做的tableView的简单变化。 我有一个自定义表视图的背景,我想改变页眉和页脚文本颜色,

只有文本颜色。

我已经看到了互联网,通常我们必须使用委托方法给表查看一个全新的观点上,但我只会改变文字颜色(如果不可能性,阴影)...

有一个简单的办法做到这一点,避免创建一个新的整个看法

请帮我。

谢谢

Answer 1:

如果你想页眉/页脚中不仅仅是一个自定义字符串其他任何方式进行自定义,你需要创建一个UIView。

这是记录在在UITableViewDataSource文档:

的tableView:titleForHeaderInSection:

讨论表视图使用用于区段标题的标题的固定字体样式。 如果你想有一个不同的字体样式,在委托方法的tableView返回自定义视图(例如,一个UILabel对象):viewForHeaderInSection:代替。



Answer 2:

很抱歉,但自定义您的标题的字体颜色的唯一途径是建立在委托方法一个UIView

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

如果你看一下贴出答案在这里 ,你可以看到落实到你的应用程序这是一个非常简单的方法。 所有你需要做的就是复制和粘贴功能即进入你的表视图的数据源,然后更改的UILabel属性是你希望它是什么。

下面是从该职位,以供参考的代码:

Originally posted by Harsh:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,200,300,244)];
    tempView.backgroundColor=[UIColor clearColor];

    UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,300,44)];
    tempLabel.backgroundColor=[UIColor clearColor]; 
    tempLabel.shadowColor = [UIColor blackColor];
    tempLabel.shadowOffset = CGSizeMake(0,2);
    tempLabel.textColor = [UIColor redColor]; //here u can change the text color of header
    tempLabel.font = [UIFont fontWithName:@"Helvetica" size:fontSizeForHeaders];
    tempLabel.font = [UIFont boldSystemFontOfSize:fontSizeForHeaders];
        tempLabel.text=@"Header Text";

    [tempView addSubview:tempLabel];

    [tempLabel release];
    return tempView;
}


Answer 3:

考虑到如果设置页眉/页脚没有UIView你逝去的一个子类NSString ,但目前无法完成你想要的东西,而无需创建一个UIView



文章来源: Change TableView Header Text Color