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"?
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.
This should help you:)
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With