Skip to content

NSMutableParagraphStyle:allowsDefaultTighteningForTruncation 属性 ​

allowsDefaultTighteningForTruncation 属性是文字要被截断之前,系统是否先把字距收紧一点试试。

值 ​

布尔。

true:先收紧字距,收紧后放得下就不截断。false:不收紧,直接截断。

  • 可读,可写。
  • 默认值是 false(未在模拟器验证)。
  • 段落样式放进富文本时放的是当时的一份副本。之后再改这个属性,已经建好的富文本不变,要重新建一个富文本再交给视图。

写错时 ​

写入的值按 Boolean() 转。

示例 ​

js
const style = new NSMutableParagraphStyle();
style.allowsDefaultTighteningForTruncation = true;
console.log(style.allowsDefaultTighteningForTruncation);
const text = new NSAttributedString('第一行\n第二行', { paragraphStyle: style });

结果:控制台输出 true。富文本里这两行按这个设置排版,屏幕上的效果未在模拟器验证。

对应的 iOS API ​

NSMutableParagraphStyle.allowsDefaultTighteningForTruncation。

参见 ​