UILabel์— ๋“ค์–ด๊ฐ„ text๋ฅผ ๋ชจ๋‘ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ? ์‰ฌ์›Œ๋ณด์ด์ง€๋งŒ ์˜์™ธ๋กœ ์‚ฝ์งˆ์„ ํ•˜๋Š” ๋ถ€๋ถ„์ด๋‹ค. ๊ฐ„๋‹จํ•˜๊ฒŒ ์•Œ์•„๋ณด์ž.

line ์ˆ˜๊ฐ€ ๊ฒฐ์ •๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ

self.titleLabel.numberOfLines = 2
self.titleLabel.lineBreakMode = .truncatedTail
 
self.titleLabel <- Layouts()
    .resize(width: maxWidth)
    .move(to: .bottom, of: self.nicknameLabel, gap: Constants.labelSpace, alignment: nil)
    .move(to: .right, of: self.iconImageView, gap: Constants.imageLabelSpace, alignment: nil)
  1. ๋จผ์ € ํ‘œํ˜„๋˜๊ณ  ์‹ถ์€ ๋ผ์ธ ์ˆ˜๋ฅผ ์„ค์ •ํ•œ๋‹ค.
  2. ๊ทธ๋Ÿผ ๊ทธ ๋ผ์ธ ์ˆ˜๋ฅผ ๋„˜์–ด๊ฐ”์„ ๋•Œ ์–ด๋–ป๊ฒŒ ๋  ๊ฒƒ์ธ๊ฐ€? ์ด ์งˆ๋ฌธ์ด ๋– ์˜ค๋ฅธ๋‹ค. ์„ค์ •ํ•ด์ฃผ์ž.
  3. ํ‘œํ˜„๋˜๊ณ  ์‹ถ์€ ๊ฐ€๋กœ ๊ธธ์ด๋งŒ ์ง€์ •ํ•ด์ค€๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์‹œ์Šคํ…œ์ด ๊ณ„์‚ฐํ•  ์ •๋ณด๊ฐ€ ๋ชจ๋‘ ์ฃผ์–ด์กŒ๊ธฐ ๋•Œ๋ฌธ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.
  4. ๋งˆ์ง€๋ง‰์œผ๋กœ ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด์ฃผ์ž.

line ์ˆ˜๊ฐ€ ๊ฒฐ์ •๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ

self.titleLabel.numberOfLines = .zero
 
self.titleLabel <- Layouts()
    .resize(width: maxWidth)
    .sizeToFit()
    .move(to: .bottom, of: self.nicknameLabel, gap: Constants.labelSpace, alignment: nil)
    .move(to: .right, of: self.iconImageView, gap: Constants.imageLabelSpace, alignment: nil)
  1. numberOfLines๋ฅผ 0๋กœ ์„ค์ •ํ•œ๋‹ค. ๋ฌธ์„œ์— ๋ช…์‹œ์ ์œผ๋กœ ๋‚˜์™€์žˆ๋‹ค. ๋ชจ๋“  ์ค„์„ ํ‘œ์‹œํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ ์„ค์ •ํ•ด๋ผ.
  2. ๋ชจ๋“  ์ค„์„ ํ‘œํ˜„ํ•œ๋‹ค๊ณ  ํ–ˆ๋Š”๋ฐ, fitํ•˜๊ฒŒ ํฌ๊ธฐ๋ฅผ ๋งž์ถ”๋ผ๋Š” ๊ฒƒ์€ ๋ง์ด ์•ˆ๋œ๋‹ค. ํฌ๊ธฐ๋ฅผ ์•Œ๋ ค์ค˜์•ผ ๋งž์ถ”์ง€.
  3. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์šฐ์„ ์ ์œผ๋กœ ๋‚ด ์‚ฌ์ด์ฆˆ์— ๋Œ€ํ•ด ์•Œ๋ ค์ค˜์•ผ ํ•œ๋‹ค.
  4. ๊ทธ ๋‹ค์Œ์— ๊ทธ ํฌ๊ธฐ์— ๋งž๊ฒŒ ์‚ฌ์ด์ฆˆ๋ฅผ ๋งž์ถ˜๋‹ค.
  5. ๋‹ค์Œ์œผ๋กœ ์œ„์น˜๋ฅผ ์กฐ์ •ํ•ด์ค€๋‹ค.

Reference