[英]UILabel multiline truncate middle as a whole string not working
我正在使用2行的UILabel
。 我想讓它像
"Had the best experience ever! She is very gener... – Mary"
將中間部分截斷,但我無法達到同樣的效果。
還應考慮label
必須為2行,並且名稱末尾必須出現。 我的label
初始化代碼如下
self.labelMessage = [[VTUIKit labelSecondary] addToSuperview:self];
self.labelMessage.numberOfLines = 2;
self.labelMessage.font = kVTFontSecondaryVeryTiny;
self.labelMessage.textColor = kVTColorGrey300;
self.labelMessage.lineBreakMode = NSLineBreakByTruncatingMiddle;
self.labelMessage.f_width = [VTReviewDisplayCell cellSize].width - 16;
並用於設置label
文本
NSString *reviewString = [NSString stringWithFormat:@"%@ - %@", self.model.message, self.model.customer_user.first_name];
self.labelMessage.text = reviewString;
我不明白為什么它不能正常工作。
任何幫助將非常感激。
嘗試以下代碼
UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(40,100, 250, 60)];
contentLabel.numberOfLines = 2;
contentLabel.text = @"Had the best experience ever! She is very generally uwuq wuqe iwqwq – Mary";
contentLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
[self.view addSubview:contentLabel];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.