iOS UILabel LineBreakMode

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any iOS Question?