プロジェクトでを使用し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:
私は次のようなテキストを 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];
}
余分なテキストは単に破棄されます。デフォルトでは、テキストが切り取られたことを示す省略記号は追加されません。この問題の解決策はありますか?
ありがとう、ラージ