iOS LineBreakMode


Example

Using code

UILabel.lineBreakMode: NSLineBreakMode

Swift

label.lineBreakMode = .ByTruncatingTail
  • .ByWordWrapping
  • .ByCharWrapping
  • .ByClipping
  • .ByTruncatingHead
  • .ByTruncatingTail
  • .ByTruncatingMiddle

Swift 3

label.lineBreakMode = .byTruncatingTail
  • .byWordWrapping
  • .byCharWrapping
  • .byClipping
  • .byTruncatingHead
  • .byTruncatingTail
  • .byTruncatingMiddle

Objective-C

[label setLineBreakMode:NSLineBreakByTruncatingTail];
  • NSLineBreakByWordWrapping
  • NSLineBreakByCharWrapping
  • NSLineBreakByClipping
  • NSLineBreakByTruncatingHead
  • NSLineBreakByTruncatingTail
  • NSLineBreakByTruncatingMiddle

Using storyboard

This can also be set in the attributes inspector of a UILabel:

enter image description here enter image description here

Constants

  • Word Wrapping - wrapping occurs at word boundaries, unless the word itself doesn’t fit on a single line
  • Char Wrapping - wrapping occurs before the first character that doesn’t fit
  • Clipping - lines are simply not drawn past the edge of the text container
  • Truncating Head - 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 ellipsis glyph
  • Truncating Tail - 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 ellipsis glyph
  • Truncating Middle - 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 ellipsis glyph