2010-09-07 110 views
4

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

的過多的文本只是被丟棄,缺省情況下不會添加省略號以指示文本被剪切。任何解決這個問題的方法?

感謝, 拉吉

回答

-1

我相信你所使用的是有機會從OOF檢查appstore.Just甩一旦你上傳前的私有API Three20。 一般來說,你可以設置任何設置任何自定義按鈕,其上設置標題

[button setContentHorizo​​ntalAlignment:UIControlContentHorizo​​ntalAlignmentLeft]; [button setTitleEdgeInsets:UIEdgeInsetsMake(0.0,10.0,0.0,0.0)]; - 此行可用於設置標題邊緣。希望能幫助到你。