【问题标题】:UITableViewCell Font size does not changeUITableViewCell 字体大小不变
【发布时间】:2015-04-23 10:50:31
【问题描述】:

我有一个自定义 UITableViewCell 正在 tableView 中显示。这个 UITableViewCell 是从一个 nib 文件生成的。 UITableViewCell 中有一个 UILabel。下面给出了代码。显然我试图将字体大小减小到固定大小,但似乎没有任何效果。这是我目前正在做的设置字体大小的操作。

在 UITableViewCell(这是附加到笔尖的 .m 文件)中,这是我所做的

- (void)awakeFromNib
{
    UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 4.0 ];
        self.LabelMyLabel.font  = myFont;
}

这就是 TableView 的创建方式

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *TransferIdentifier = @"TransferTableItem";

    FileTransferTableCell *cell = [tableView dequeueReusableCellWithIdentifier:TransferIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FileCustomTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    //Set the text in the UITableViewCell here
    cell.textLabel.text = [self.MyArray objectAtIndex:indexPath.row];
    return cell;
}

如果有人能帮我弄清楚为什么我的 textsize 总是恒定的,我将不胜感激(我还在界面生成器中减小了 UITableViewCell 中标签的字体大小)?

【问题讨论】:

  • 尝试将您的代码移动到 viewDidLoad 而不是 awakeFromNib
  • @Wongzigii 表格单元格中没有viewDidLoad
  • 您是否仔细检查了您的笔尖连接?是不是叫 textLabel 的标签?
  • 是的,我有 - 我也重做了它们,但它是一样的
  • 你这里有一个严重的不匹配。您通过说cell.textLabel.text 设置文本,但通过说self.LabelMyLabel.font 设置字体。这些不可能都是正确的。标签是textLabel 还是LabelMyLabel

标签: ios objective-c iphone uitableview


【解决方案1】:

标签字体设置正常。问题是您设置了错误标签的 text。你是说:

cell.textLabel.text = [self.MyArray objectAtIndex:indexPath.row];

那是错误的标签。您想设置LabelMyLabel 的文本,而不是textLabel。它们是两个不同的标签。

【讨论】:

    【解决方案2】:

    cell.textLabel.text 更改为cell.LabelMyLabel,因为它已在您的笔尖中设置。

    【讨论】:

      猜你喜欢
      • 2011-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 2021-08-08
      • 2016-04-22
      • 2013-03-29
      相关资源
      最近更新 更多