I use TTStyledTextLabel in my project to analyze hyperlinks, everything works fine. The only problem I encountered is to truncate long text - show ellipses if the text does not fit the borders of the TTStyledTextLabel .
In other words, I need the same behavior as UILabel, which adds ellipses to indicate that some text is cropped. I searched in the TTStyledTextLabel and TTStyledText , there are no conditions for this. The following is the code I used in my subclass of UITableViewCell to set the TTStyledTextLabel frame 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;
And in tableView:cellForRowAtIndexPath: I set the text like this to my 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]; }
Excess text is simply discarded, ellipses are not added by default to indicate that the text is cropped. Any solutions to this problem?
Thanks Raj
source share