如何在分组类型 UITableView 中更改标题的字体颜色? [英] How to change font color of the title in grouped type UITableView?

查看:27
本文介绍了如何在分组类型 UITableView 中更改标题的字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分组类型的表格视图,它看起来很酷.

I have a grouped type table view and it looks pretty cool.

但是,如果我将表格的背景颜色更改为黑色,标题就会变得不清楚.

But, if I change the background color of the table to black, the titles becomes unclear.

是否可以更改字体颜色及其样式以使其更具可读性?我应该实现 tableView:viewForHeaderInSection: 方法吗?

Is it possible to change the font color and its styles so that I can make it more readable? Should I implement the tableView:viewForHeaderInSection: method?

推荐答案

是的...现在效果很好!

Yes... It works great now!

我创建了 tableView:viewForHeaderInSection: 方法并创建了一个 UIView

I created tableView:viewForHeaderInSection: method and created a UIView

UIView *customTitleView = [ [UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];

然后我创建了一个 UILabel &设置文本值 &标签的颜色.然后我将标签添加到视图

Then i created a UILabel & set the text values & colors to the label. Then i added the label to the view

UILabel *titleLabel = [ [UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
titleLabel.text = @"<Title string here>";
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
[customTitleView addSubview:titleLabel];

所以我的 tableView:viewForHeaderInSection: 方法看起来像...

So my tableView:viewForHeaderInSection: method looks like...

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

    UIView *customTitleView = [ [UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
    UILabel *titleLabel = [ [UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
    titleLabel.text = @"<Title string here>";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    [customTitleView addSubview:titleLabel];
    return customTitleView;
}

我们应该添加 tableView:heightForHeaderInSection: 方法来为标题提供一些空间.

We should add tableView:heightForHeaderInSection: method for providing some space to the title.

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{
    return 44; 
}

这篇关于如何在分组类型 UITableView 中更改标题的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆