iphone - 自定义部分标题 uilabel 背景和文本

标签 iphone ios uitableview

我目前正在创建自己的自定义部分标题,但我从来没有通过代码进行任何文本编辑。我用来填充自定义标题的新方法正在做一些奇怪的事情,如图所示 enter image description here下面

我想将文本更改为白色并稍微加粗,同时使白色背景透明..

这是我用来做这件事的代码

- (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/

相关文章:

javascript - iPhone 4+ 默认为 320 像素的网络应用程序分辨率,我想使用完整的 640 像素

ios - Unity 在 iPhone 上的 GetCloudProjectId() 崩溃

iphone - 如何在图像上实现 alpha 渐变?

iphone - UITableviewController 失去对 tableview 的引用

ios - 如何在 iOS 中为单元格分隔符设置图像

ios - UITableViewController 与 UITableView

iphone - 如何引用 uinavigationcontroller 堆栈中前面的 viewcontroller 属性?

iphone - 具有默认时区的 NSDateFormatter 给出的日期与 NSDate 描述方法不同

ios - iPhone 模拟器上的 CLLocationManager 失败,kCLErrorDomain Code=0

ios - UIScrollView如何设置ContentInset和ScrollerInset