I want to display first 500 character in UILabel and than display Truncate icon if there is more than 500 character available.But i dont know how can i limit 500 character to truncate the text?.
Here is my code
label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 350, self.bounds.size.width, 30)];
// In this case value of self.bounds.size.width is "427"
label2.backgroundColor = [UIColor clearColor];
label2.numberOfLines = 2;
label2.textAlignment = UITextAlignmentCenter;
label2.font = [UIFont systemFontOfSize:13];
[self addSubview:label2]
//Here is Implimentation code of my label
NSString *temp = [galleryEntryTree objectForKey:@"description"];// calling lebel text from database
coverView.label2.text = temp;
coverView.label2.adjustsFontSizeToFitWidth = NO;
coverView.label2.lineBreakMode = UILineBreakModeTailTruncation;
Just tell me guys how can i display min 500 character and than truncate it( if longer than 500)
Any help is appreciated
Just truncate the string if it's longer than 500 characters. Only caveat: make sure to not break it in the middle of a surrogate pair:
NSString *temp = [galleryEntryTree objectForKey:@"description"];
if ([temp length] > 500) {
NSRange range = [temp rangeOfComposedCharacterSequencesForRange:(NSRange){0, 500}];
temp = [temp substringWithRange:range];
temp = [temp stringByAppendingString:@" …"];
}
coverView.label2.text = temp;
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