我目前正在创建自己的自定义部分标题,但我从来没有通过代码进行任何文本编辑。我用来填充自定义标题的新方法正在做一些奇怪的事情,如图所示 下面
我想将文本更改为白色并稍微加粗,同时使白色背景透明..
这是我用来做这件事的代码
- (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 属性是你的 friend 。
And slightly bolder...
没问题! headerLabel.font = [UIFont boldSystemFontOfSize:mySize];
And make a white transparent background.
哇,哇,这是我见过的最糟糕的 setter 语法!!!大人,myLabel.backgroundColor 是一个getter,更改:
[headerLabel.backgroundColor:[UIColor clearColor]];
到:
[headerLabel setBackgroundColor:[UIColor clearColor]];
幸运的是,使用您的语法只会向 nil 发送一条消息,这会将标签的背景色默认为白色。
关于iphone - 自定义部分标题 uilabel 背景和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10168896/