effect要求是在屏幕上截取屏幕宽度的字符串3/2的显示...

希望得到您的帮助,谢谢!

if (meetModel.title.length > 18) {
    title = [NSString stringWithFormat:@"%@...", [meetModel.title substringToIndex:18]];
} else {
    title = meetModel.title;
}


这种方法不能满足我的需求。页面显示为中文。

最佳答案

我不清楚您的问题,但我认为您需要添加类似的内容(示例在Swift 3.1中)。这个想法是您应该设置宽度约束,并且如果文本大于此宽度,则应将其自动截断。

yourLabel.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.66).isActive = true

// It's needed for adding three dots in the end, if the string is larger then it should be
yourLabel.adjustsFontSizeToFitWidth = false
yourLabel.lineBreakMode = .byTruncatingTail

关于ios - iOS截取指定宽度的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45565495/

10-12 00:16
查看更多