我想在UILabel中顯示前500個字符,並且如果有超過500個字符可用,則顯示截斷圖標。但是我不知道如何將500個字符限制爲截斷文本?將UILabel限制爲500個字符並截斷IOS中的UIlab
這裏是我的代碼
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;
只要告訴我,大家好我怎麼能顯示分鐘500字,比截斷它(若超過500)
任何幫助表示讚賞
coverView.label2.lineBreakMode = UILineBreakModeWordWrap;並調整你的身高或動態增加身高。 – 2013-03-15 09:30:42
您可以嘗試使用NSMutableString並在設置label.text前截斷文本。 – jcesarmobile 2013-03-15 09:30:45
yourLabel.text.length在if中使用此字符串,然後使用stringbyappendingstring或stringwithformat – amar 2013-03-15 09:31:00