【问题标题】:TTTAttributedLabel sizetofit and sizeWithFont is differentTTTAttributedLabel sizetofit 和 sizeWithFont 不同
【发布时间】:2015-07-16 18:30:54
【问题描述】:

我正在使用 TTTAttributedLabel,我通常在我的 tableview 单元格中使用 sizetofit。之后,我在单元格高度计算中使用 sizeWithFont。我是这样设置 TTTAttributedLabel 的。

[self.attributedLabel setText:@"Test\n\n\n\n"];
CGSize contentSize = [self.attributedLabel.text sizeWithFont:self.attributedLabel.font
                                      constrainedToSize:CGSizeMake(CGRectGetWidth(self.attributedLabel.frame), 1000)
                                          lineBreakMode:NSLineBreakByWordWrapping];

[self.attributedLabel sizeToFit];

我注意到高度不同。我得到了这样的输出。所以我猜是错的。我可以知道如何解决吗?我正在 iOS 8 设备上进行测试。

【问题讨论】:

    标签: ios uilabel sizetofit sizewithfont tttattributedlabel


    【解决方案1】:

    您应该使用TTTAttributedLabel 的内置方法来计算尺寸

    +[TTTAttributedLabel sizeThatFitsAttributedString: withConstraints:limitedToNumberOfLines:,它将为您返回正确的CGSize

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      相关资源
      最近更新 更多