【问题标题】:Truncate text in TTStyledTextLabel截断 TTStyledTextLabel 中的文本
【发布时间】:2010-09-07 06:58:43
【问题描述】:

我在我的项目中使用TTStyledTextLabel 来解析超链接,一切正常。我面临的唯一问题是截断长文本 - 如果文本不适合 TTStyledTextLabel 的范围,则显示省略号。

换句话说,我需要与 UILabel 相同的行为,它添加省略号以指示某些文本已被剪切。我在TTStyledTextLabelTTStyledText 类中进行了搜索,没有任何规定可以实现这一点。以下是我在 UITableViewCell 子类中使用的代码,用于适当地设置 TTStyledTextLabel 的框架:

-(void) layoutSubviews
{
    [super layoutSubviews];
.
.
.
    CGSize maxSize = CGSizeMake(self.contentView.frame.size.width -TEXT_OFFSET_WIDTH, TT_TEXT_MAX_HEIGHT);
    [[[self textLabelTTStyled] text] setWidth:maxSize.width];
    [[self textLabelTTStyled] sizeToFit];
    double heigthForTTLabel = [[[self textLabelTTStyled] text] height];
    if (heigthForTTLabel > maxSize.height)
        heigthForTTLabel = maxSize.height;  // Do not exceed the maximum height for the TTStyledTextLabel.
**// The Text was supposed to clip here when maximum height is set!**
    CGSize mTempSize = CGSizeMake([[[self textLabelTTStyled] text] width], heigthForTTLabel);
    CGRect frame = CGRectMake(TEXT_OFFSET_X,TEXT_OFFSET_Y,mTempSize.width, mTempSize.height);
    self.textLabelTTStyled.frame = frame;
.
.
.
}

tableView:cellForRowAtIndexPath: 中,我将这样的文本设置为我的TTStyledTextLabel

TTStyledText *styledStatusMessage = [TTStyledText textFromXHTML:@"This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on? This is a really long text, how long can this go on?"
    lineBreaks:YES URLs:YES];

if (nil == styledStatusMessage) {
  styledStatusMessage = [TTStyledText textWithURLs:[statusMessage title] lineBreaks:YES];
  [[cell textLabelTTStyled] setText:styledStatusMessage];
}

过多的文本只是被丢弃,默认情况下不添加省略号以指示文本被剪切。这个问题有什么解决办法吗?

谢谢, 拉杰

【问题讨论】:

    标签: iphone objective-c ipad three20 ttstyledtextlabel


    【解决方案1】:

    我相信您使用的是私有 api Three20,它可能会被应用商店拒绝。上传前请检查一次。 一般来说,您可以设置任何带有设置标题的自定义按钮

    [按钮 setContentHorizo​​ntalAlignment:UIControlContentHorizo​​ntalAlignmentLeft]; [按钮 setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 10.0, 0.0, 0.0)]; - 此行可用于设置标题边缘。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多