Swa*_*oid 5 iphone uilabel ios ios5
我想在UILabel中显示前500个字符,如果有超过500个字符,则显示截断图标.但我不知道如何限制500个字符来截断文本?
这是我的代码
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;
Run Code Online (Sandbox Code Playgroud)
告诉我们伙计们如何显示最少500个字符而不是截断它(如果超过500个)
任何帮助表示赞赏
Nik*_*uhe 12
如果字符串长度超过500个字符,则截断该字符串.只有警告:确保不要在代理对中间打破它:
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;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6522 次 |
最近记录: |