【问题标题】:tableview header in two rows两行表格视图标题
【发布时间】:2011-01-19 01:34:07
【问题描述】:

我是意大利人,很抱歉我的“丑陋”英语!

我正在使用 UITableview 并且我的(动态)标题太长了! 所以我想把标题分成两行……有可能吗?

我尝试使用“label.numberOfLines = 2”(或 = 0),但它不起作用!

这是代码:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   UILabel *label = [[[UILabel alloc] init] autorelease];
    label.backgroundColor = [UIColor clearColor];

    NSString *header1 = [NSString stringWithFormat:@"Between %@ and %@ \n (33ª and 37ª week)", dateString1, dateString2];

    if (section == 0){
            label.text = header1;
            label.frame = CGRectMake(0, 6, 300, 30);
    } else
    //the others header

    label.numberOfLines = 2;

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
    [view autorelease];
    [view addSubview:label];

    return view;}

谢谢!!

【问题讨论】:

    标签: iphone xcode uitableview header uilabel


    【解决方案1】:

    label.numberOfLines = 2 只会显示标签的高度是否足以容纳两行。此外,行高将取决于字体大小。确保标签足够高以适应给定字体大小的两行文本。尝试使字体更小或标签更大。

    【讨论】:

      【解决方案2】:

      您甚至应该在 else 上设置标签的框架,特别是因为它需要更大以容纳两行文本。

      你可以这样做:

          label.frame = CGRectMake(0, 0, 320, 30); // trying bigger heights
          label.numberOfLines = 2;
          // ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-26
        • 1970-01-01
        • 1970-01-01
        • 2018-02-25
        • 2019-09-16
        • 2015-07-03
        相关资源
        最近更新 更多