自定义节标题uilabel背景和文本 [英] customize section header uilabel background and text
问题描述
我当前正在创建自己的自定义节标题,但是我从未通过代码进行任何文本编辑..而我用来填充自定义标题的新方法正在做一些奇怪的事情,如图所示:
I am currently creating my own custom section headers but I have never dont any text editing via code.. and my new method that I am using to populate my custom header is doing some weird things as shown below
我想将文本更改为白色并稍加粗体,并使白色背景透明.
I would like to change the text to white and be slightly bolder and also make the white background transparent..
这是我用来执行此操作的代码
this is the code I am using to do this
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor grayColor]];
// Add the label
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.5, 20, 20)];
// do whatever headerLabel configuration you want here
headerLabel.text = [self tableView:tableView titleForHeaderInSection:section];
[headerView addSubview:headerLabel];
// Return the headerView
return headerView;
}
我已经尝试过了
[headerLabel.backgroundColor:[UIColor clearColor]];
等,但不起作用:(
推荐答案
我想将文本更改为白色...
I would like to change the text to white...
UILabel的textColor属性是您的朋友.
UILabel's textColor property is your friend here.
稍大胆...
没问题! headerLabel.font = [UIFont boldSystemFontOfSize:mySize];
并设置白色透明背景.
And make a white transparent background.
哇,哇,这是有史以来最糟糕的setter语法!我的主人myLabel.backgroundColor是一个 getter ,更改为:
Whoa, whoa, that is the worst setter syntax ive ever seen!!! My lord, myLabel.backgroundColor is a getter, change:
[headerLabel.backgroundColor:[UIColor clearColor]];
收件人:
[headerLabel setBackgroundColor:[UIColor clearColor]];
对您来说幸运的是,使用您的语法会向nil发送一条消息,这默认将标签的背景色设置为白色.
Lucky for you, using your syntax would have just sent a message to nil, which is defaulting the background color of your label to white.
这篇关于自定义节标题uilabel背景和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!