31
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

UILabelの改行まとめ

UILabelの改行の種類をいつも調べてる気がするので備忘録代わりにまとめた

let label = UILabel(frame: .zero)
label.lineBreakMode = .byWordWrapping

lineBreakModeの型であるNSLineBreakModeのドキュメントを見ると、改行方法は6種類ある

byWordWrapping

Wrapping occurs at word boundaries, unless the word itself doesn’t fit on a single line. See Characters and Grapheme Clusters in String Programming Guide for a discussion of issues related to determining word boundaries.

20170317195406.png

単語の境界で折り返す

byCharWrapping

Wrapping occurs before the first character that doesn’t fit.

20170317200325.png

文字で折り返す

byClipping

Lines are simply not drawn past the edge of the text container.

20170317200325.png

折り返さず、端を超えた文字は表示されない

byTruncatingHead

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. Although this mode works for multiline text, it is more often used for single line text.

20170317200802.png

文字列末尾が表示され、行の先頭に三点リーダ

byTruncatingTail

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. Although this mode works for multiline text, it is more often used for single line text.

20170317200954.png

文字列先頭が表示され、行の末尾に三点リーダ

byTruncatingMiddle

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. This mode is used for single-line layout; using it with multiline text truncates the text into a single line.

20170317201055.png

文字列先頭と末尾が表示され、中央に三点リーダ

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
31
Help us understand the problem. What are the problem?