[英]UILabel multiline truncate middle as a whole string not working
I am using a UILabel
which is of 2 lines. 我正在使用2行的
UILabel
。 I want to make it like 我想让它像
"Had the best experience ever! She is very gener... – Mary"
truncating middle portion but I am unable to achieve the same result. "Had the best experience ever! She is very gener... – Mary"
将中间部分截断,但我无法达到同样的效果。
Also consider that label
must be of 2 line and name at the end must appear. 还应考虑
label
必须为2行,并且名称末尾必须出现。 My code for label
for initialisation is as follow 我的
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;
And for setting label
text 并用于设置
label
文本
NSString *reviewString = [NSString stringWithFormat:@"%@ - %@", self.model.message, self.model.customer_user.first_name];
self.labelMessage.text = reviewString;
I dont understand why its not working properly. 我不明白为什么它不能正常工作。
Any help would be much appreciated. 任何帮助将非常感激。
Try with below code 尝试以下代码
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.