问题描述
我有一个分组类型的tableview,它看起来很酷。但是,如果我把表格的背景颜色改为黑色,标题就变得不清楚了。是有可能改变字体颜色&它的风格?所以我可以使它更具可读性。我应该实现 tableView:viewForHeaderInSection:
方法吗?
..它现在伟大的工程!
$ b 我创建了 tableView:viewForHeaderInSection:
方法并创建了一个UIView
UIView * customTitleView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,44)];
然后我创建了一个UILabel&设置文本值&颜色的标签。然后,我添加了标签到视图
pre $ u $ c $ U $ UELabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,300 ,44)];
titleLabel.text = @<标题字符串在这里>;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
[customTitleView addSubview:titleLabel];
所以我的 tableView:viewForHeaderInSection:
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)部分{$ b $($)$ $ $
$ b $
$ b UIView * customTitleView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,44)];
UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,300,44)];
titleLabel.text = @<标题字符串在这里>;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
[customTitleView addSubview:titleLabel];
返回customTitleView;
我们应该添加 tableView:heightForHeaderInSection:$ (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:用于提供一些空间标题的方法。
- (NSInteger)部分
{
return 44;
}
I have a grouped type tableview and it looks pretty cool.
But, if i change the background color of the table to black, the titles becomes unclear.
Is it possible to change the font color & its styles? So that i can make it as more readable. Should i implement the tableView:viewForHeaderInSection:
method?
Yes... It works great now!
I created tableView:viewForHeaderInSection:
method and created a UIView
UIView *customTitleView = [ [UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
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];
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;
}
We should add tableView:heightForHeaderInSection:
method for providing some space to the title.
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44;
}
这篇关于如何更改组合类型UITableView的标题的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!