如何在Facebook的“继续阅读”等文本末尾添加按钮? [英] How to add button to the end of text like Facebook's "Continue reading"?

查看:368
本文介绍了如何在Facebook的“继续阅读”等文本末尾添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当状态帖子太长时,Facebook应用程序会剪切文本并在最后添加继续阅读。它如何知道在哪里剪切文本并添加...继续阅读?

When a status post is too long, Facebook app cuts the text and adds "Continue Reading" at the end. How does it know where to cut the text and add "... Continue Reading"?

不只是向textView或label添加按钮,而是如何剪切字符串。
在下图中,例如,我将行数限制为7.我可以在textView或标签的右下角放置一个按钮,但它可能会重叠某些字符。

Not just adding a button to textView or label but how do I cut the string. In picture below, for example, I limited number of lines to 7. I could just place a button over lower right corner of the textView or label but it might be overlap some characters.

推荐答案

这应该可以帮助你:)

NSString *str=self.strQuestionTitle;

CGRect rect=CGRectMake(51, 16, 257, 0);

CGSize size=[str sizeWithFont:self.lblQuestion.font constrainedToSize:CGSizeMake(257, 3000) lineBreakMode:self.lblQuestion.lineBreakMode];
int lines=(size.height/self.lblQuestion.font.pointSize);
self.lblQuestion.numberOfLines=lines;
rect.size=size;
if(lines>2)
{
    if(lines==3 &&[str length]>66)
    {
        str=[str substringToIndex:66];
    str=[str stringByAppendingString:@"...Read More"];
    size=[str sizeWithFont:self.lblQuestion.font constrainedToSize:CGSizeMake(257, 67) lineBreakMode:self.lblQuestion.lineBreakMode];

    int lines=(size.height/self.lblQuestion.font.pointSize);
    self.lblQuestion.numberOfLines=lines;

    rect.size=CGSizeMake(257, 67);
    }
    else if(lines>3)
    {
        str=[str stringByAppendingString:@"...Read More"];
        size=[str sizeWithFont:self.lblQuestion.font constrainedToSize:CGSizeMake(257, 67) lineBreakMode:self.lblQuestion.lineBreakMode


              ];

        int lines=(size.height/self.lblQuestion.font.pointSize);
        self.lblQuestion.numberOfLines=lines;

        rect.size=CGSizeMake(257, 67);
    }

    //self.lblQuestion.lineBreakMode=NSLineBreakByTruncatingHead;
}

这篇关于如何在Facebook的“继续阅读”等文本末尾添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆