我在我的項目中使用TTStyledTextLabel
來解析超鏈接,它一切正常。我面臨的唯一問題是截斷長文本 - 如果文本不符合TTStyledTextLabel
的範圍,則顯示省略號。在TTStyledTextLabel中截斷文本
換句話說,我需要與UILabel相同的行爲,它會添加省略號以指示某些文本被剪切。我在TTStyledTextLabel
和TTStyledText
類中搜索過,沒有規定要實現這一點。以下是我在我的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];
}
的過多的文本只是被丟棄,缺省情況下不會添加省略號以指示文本被剪切。任何解決這個問題的方法?
感謝, 拉吉