iphone - 截断 TTStyledTextLabel 中的文本

标签 iphone objective-c ipad three20 ttstyledtextlabel

我在我的项目中使用 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];
}

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

谢谢, 拉吉

最佳答案

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

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

关于iphone - 截断 TTStyledTextLabel 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3656395/

相关文章:

iphone - 在 Cocoa Touch 环境中使用 AppKit 的等效 NSBox 是什么?

iphone - 检测动画的完成

iphone - Objective-C Xcode : Tableview detailitem empty

iOS - 绘制数千个符号的最佳方式

iphone - 什么是 iOS 6 用户代理字符串?

ios - 如何在自定义 UIView 中从 ViewController 传递数据

iphone - 为什么无法通过 tableview 加载?

ios - 使用内置的栏按钮图标

iphone - 如何以编程方式安装 iOS 应用程序?

ios - iPad 不检测摇动事件