【问题标题】:re size the UITable view textlabel调整表格视图文本标签的大小
【发布时间】:2011-06-16 05:45:44
【问题描述】:

我创建了一个 UITableView 并在 cellForRowAtIndexPath

中编写了以下代码
static NSString *CellIdentifier = @"RootViewControllerCellIdentifier";

UITableViewCell *cell = [self.tableView queueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    cell.selectionStyle = UITableViewCellSelectionStyleGray;    

}

// Set appropriate labels for the cells.
switch (indexPath.row) {
    case 0:
        cell.textLabel.text = @"Static Scenes";             
        **[cell.textLabel setFrame:CGRectMake(200, 20, 500,600)];**
        cell.imageView.image=[UIImage imageNamed:@"RunOptionsImage.png"];
        cell.imageView.frame=CGRectMake(15, 20, 55, 65);
        break;

从上面的代码可以理解,我有一个名为 Static Sc​​enes 的 tableview 单元格 textLabel。

在这段代码中 [cell.textLabel setFrame:CGRectMake(200, 20, 500,600)]; 我打算设置 textLabel 的框架。但它不会根据我设置的框架调整大小。 我也使用了这个 cell.textLabel.frame = CGRectMake(200, 20, 500,600) 代码。 谁能告诉我调整文本标签大小的好方法。

【问题讨论】:

  • 如果任何答案有帮助,您应该接受它。如果您在此问题上需要任何进一步的帮助,请提及。

标签: cocoa-touch ipad uitableview textlabel


【解决方案1】:

除了更改文本标签的大小之外,您还需要在tableView:heightForRowAtIndexPath: 方法中返回适当的高度。否则,任何布局更改都不会反映。

【讨论】:

    【解决方案2】:

    据我了解,除了 cellForRowAtIndexPath 中单元格内的单元格内容外,您不应修改任何内容。不久前查看我的questions 之一。总结:

    所以黄金法则是:永远不要改变 出队后的细胞结构 它。如果您需要更改 结构然后使用不同的单元格 ID。 当然更可定制的是 细胞越容易,就越有可能 重复使用它们。

    【讨论】:

      【解决方案3】:

      我相信 UITableView 实际上是在请求 cellForRowAtIndexPath 之后布局单元格。虽然我同意 donalbain 的回答,即您应该使用可自定义的单元格,但我相信您可以通过更改此委托方法中的框架来获得所需的功能

      - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-03-20
        • 1970-01-01
        • 2016-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多