2010-09-07 11 views
4

J'utilise un TTStyledTextLabel dans mon projet pour analyser les hyperliens, tout fonctionne bien. Le seul problème auquel je suis confronté est de tronquer un long texte - montrer des ellipses si le texte ne rentre pas dans les limites de TTStyledTextLabel.Tronquer le texte dans TTStyledTextLabel

En d'autres termes, j'ai besoin du même comportement qu'un UILabel qui ajoute des ellipses pour indiquer que du texte est coupé. J'ai cherché dans TTStyledTextLabel et TTStyledText classes, il n'y a aucune disposition pour y parvenir. Ce qui suit est le code que je l'ai utilisé dans mon UITableViewCell sous-classe pour définir le cadre de TTStyledTextLabel appropriée:

-(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; 
. 
. 
. 
} 

Et dans le tableView:cellForRowAtIndexPath: Je suis en train de texte comme à mon 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]; 
} 

Le le texte excessif est simplement rejeté, les ellipses ne sont pas ajoutées par défaut pour indiquer que le texte est coupé. Des solutions à ce problème?

Merci, Raj

Répondre

-1

je crois que vous utilisez un api privé Three20 qui est d'avoir une chance OOF rejet de chèque appstore.Just une fois avant de télécharger. Généralement, vous pouvez définir n'importe quel bouton personnalisé avec le titre du paramètre

[button setContentHorizontalAlignment: UIControlContentHorizontalAlignmentLeft]; [bouton setTitleEdgeInsets: UIEdgeInsetsMake (0.0, 10.0, 0.0, 0.0)]; - Cette ligne peut être utilisée pour définir les bords du titre. J'espère que cela aide.