lineBreakMode
用于包装和截断标签文本的技术。
@property(nonatomic) NSLineBreakMode lineBreakMode;
讨论
如果您在 iOS 6 或更高版本中使用样式文本,请分配新值
到此属性会导致将换行模式应用于
attributesText 属性中的整个字符串。如果你想
仅将换行模式应用于文本的一部分,创建一个新的
属性字符串与所需的样式信息并将其关联
与标签。如果您不使用样式文本,则此属性
适用于 text 属性中的整个文本字符串。
此属性在正常绘图和案例中都有效
必须减小字体大小以适应标签的文本
边界框。这个属性被设置为 NSLineBreakByTruncatingTail
默认。
重要提示:如果此属性设置为导致文本换行的值
到另一行,设置
adjustsFontSizeToFitWidth 或 adjustsLetterSpacingToFitWidth 属性
是。
特别注意事项
在 iOS 5 及更早版本中,此属性的类型为 UILineBreakMode。
可用性
Available in iOS 2.0 and later.
NSLineBreakMode
这些常量指定当一行太长时会发生什么
容器。
enum {
NSLineBreakByWordWrapping = 0,
NSLineBreakByCharWrapping,
NSLineBreakByClipping,
NSLineBreakByTruncatingHead,
NSLineBreakByTruncatingTail,
NSLineBreakByTruncatingMiddle
};
typedef NSUInteger NSLineBreakMo
常量
NSLineBreakByWordWrapping
Wrapping occurs at word boundaries, unless the word itself doesn’t fit on a single line.
Available in iOS 6.0 and later.
Declared in NSParagraphStyle.h.
NSLineBreakByCharWrapping
Wrapping occurs before the first character that doesn’t fit.
Available in iOS 6.0 and later.
Declared in NSParagraphStyle.h.
NSLineBreakByClipping
Lines are simply not drawn past the edge of the text container.
Available in iOS 6.0 and later.
Declared in NSParagraphStyle.h.
NSLineBreakByTruncatingHead
The line is displayed so that the end fits in the container and the missing text at the beginning of the line is indicated by an
省略号字形。虽然此模式适用于多行文本,但它是
更常用于单行文本。
Available in iOS 6.0 and later.
Declared in NSParagraphStyle.h.
NSLineBreakByTruncatingTail
The line is displayed so that the beginning fits in the container and the missing text at the end of the line is indicated by an
省略号字形。虽然此模式适用于多行文本,但它是
更常用于单行文本。
Available in iOS 6.0 and later.
Declared in NSParagraphStyle.h.
NSLineBreakByTruncatingMiddle
The line is displayed so that the beginning and end fit in the container and the missing text in the middle is indicated by an
省略号字形。虽然此模式适用于多行文本,但它是
更常用于单行文本。
Available in iOS 6.0 and later.
Declared in NSParagraphStyle.h.