【问题标题】:UITableView Header Styling - Font Color / Background / Font SizeUITableView 标题样式 - 字体颜色/背景/字体大小
【发布时间】:2013-12-10 16:44:56
【问题描述】:

我正在努力设置 UIView Header 的样式,我正在使用 IOS7 故事板和自定义单元格 - 每个都有自己的类 -

我想用白色文本实现不透明的灰色背景 - Helvetica Neue Medium Font size 16 - 初始标题隐藏在 HeightForHeaderInSection 方法中 - 到目前为止我有 -

 - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,  tableView.bounds.size.width, 30)];
    if (section == 0)
        [headerView setBackgroundColor:[UIColor clearColor]];
    else
        [headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
     [headerView setTintColor:[UIColor whiteColor]];


    return headerView;

 }

更新我的 Header 文本取自此方法 -

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section
{


    if(section == 1)
    {
        return @"Offers";
    }
    else if(section == 2)
    {
        return @"Workouts";
    }
    else
    {
    return @"Weights";
    }
}

【问题讨论】:

  • 如何给headerView添加文字?
  • 也许您应该将文本添加到headerView?抱歉,我想我不明白这个问题。
  • 对不起@llario - 在实施上述方法之前没有文本 - 它从数组中拉出并在我的 titleForHeaderInSection 方法中过滤 - 一旦我应用上述样式,它就看不见了
  • 使用此代码如何传递文本?抱歉,我看不懂这段代码
  • 在-cheers上方添加了titleforheader方法

标签: ios objective-c uitableview


【解决方案1】:

你可以这样给出viewForHeaderInSection中每个标题部分的标题:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

   UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,  tableView.bounds.size.width, 30)];

   UILabel *labelHeader = [[UILabel alloc] initWithFrame:CGRectMake (0,0,320,30);
   labelHeader.font = [UIFont ...]
   labelHeader.textColor = [UIColor whiteColor];

   [headerView addSubview:labelHeader];

if (section == 0)
    [headerView setBackgroundColor:[UIColor clearColor]];
else if (section == 1) {

    [headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
    labelHeader.text = @"Offers"
 }
else if (section == 2) {
    [headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
    labelHeader.text = @"Workouts"

 }

else {

   [headerView setBackgroundColor:[UIColor colorWithRed:156.0f/255.0f green:156.0f/255.0f blue:156.0f/255.0f alpha:0.75f]];
    labelHeader.text = @"Weights"
 }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多