C.J*_*hns 0 iphone uitableview ios
我目前正在创建自己的自定义节标题,但我从来没有通过代码进行任何文本编辑..我用来填充自定义标题的新方法正在做一些奇怪的事情,如图所示
下面
我想将文本更改为白色,稍微更大胆,并使白色背景透明..
这是我用来执行此操作的代码
- (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;
}
Run Code Online (Sandbox Code Playgroud)
我试过这个
[headerLabel.backgroundColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)
等但它不工作:(
我想将文字改为白色......
UILabel的textColor属性是你的朋友.
而且稍微大胆......
没问题! headerLabel.font = [UIFont boldSystemFontOfSize:mySize];
并制作白色透明背景.
哇,哇,这是我见过的最糟糕的setter语法!我的主人myLabel.backgroundColor是一个getter,改变:
[headerLabel.backgroundColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)
至:
[headerLabel setBackgroundColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)
幸运的是,使用您的语法只会向nil发送一条消息,这会将您的标签的背景颜色默认为白色.
| 归档时间: |
|
| 查看次数: |
1705 次 |
| 最近记录: |