Skip to content

Latest commit

ย 

History

History
73 lines (60 loc) ยท 1.92 KB

Text.md

File metadata and controls

73 lines (60 loc) ยท 1.92 KB

Text

๊ณต์‹๋ฌธ์„œ : A view that displays one or more lines of read-only text.

๊ฐ„๋‹จํ•˜๊ฒŒ ํ™”๋ฉด์— ํ…์ŠคํŠธ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋ทฐ์ด๋‹ค.

Declaration

@frozen struct Text

Overview

Text("eemdeeks")

ํ…์ŠคํŠธ๋Š” ๋ทฐ์˜ body์†์„ฑ ์•ˆ์— ์œ„์— ์ฒ˜๋Ÿผ ์„ ์–ธ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

font(_:)

ํ…์ŠคํŠธ๋Š” ์—ฌ๋Ÿฌ ํฐํŠธ๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ font(_:)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

Text("eemdeeks")
    .font(.title)

์œ„ ์ฝ”๋“œ์ฒ˜๋Ÿผ .font()์— ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ .title์ด๋‚˜ .caption๋“ฑ์„ ๋„ฃ์œผ๋ฉด ๊ธฐ๋ณธ์ ์ธ ํฐํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๋˜ํ•œ .title๊ฐ™์€ ๊ธฐ๋ณธ์ ์ธ ํฐํŠธ ๋Œ€์‹  .system()์„ ์ด์šฉํ•˜์—ฌ ํฐํŠธ ์‚ฌ์ด์ฆˆ, ๊ตต๊ธฐ, ๋””์ž์ธ๋“ฑ์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.

ex)

Text("I'm eemdeeks")
    .font(.system(size: 12, weight: .light, design: .serif))
    .italic()

lineLimit()

  • lineLimit()๋ฅผ ์ด์šฉํ•˜์—ฌ ์›ํ•˜๋Š” ์ค„ ๊ฐœ์ˆ˜๋งŒํผ์œผ๋กœ ์ œํ•œ์„ ๋‘˜ ์ˆ˜ ๋„ ์žˆ๋‹ค. ex)
Text("Helo, my name is Ddan!!! Nice to meet you. I have three brother!!"
    .lineLimit(3)

Text("Helo, my name is Ddan!!! Nice to meet you. I have three brother!!"
    .lineLimit(nil)

์ค„ ๊ฐœ์ˆ˜์— ๋Œ€ํ•œ ์ œํ•œ์„ ์ฃผ์ง€ ์•Š๊ณ  ์‹ถ๋‹ค๋ฉด ์œ„์— ์ฒ˜๋Ÿผ nil์„ ๋‘์–ด๋„ ๋œ๋‹ค.

  • ๊ธด ๋ฌธ์žฅ์— ๋Œ€ํ•ด์„œ๋Š” truncationMode๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ผ๋ถ€๋ฅผ ์ƒ๋žตํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
Text("Helo, my name is Ddan!!! Nice to meet you. I have three brother!!"
    .lineLimit(1)
    .truncationMode(.middle)

foregroundColor

.foregroundColor๋ฅผ ์ด์šฉํ•ด์„œ ํ…์ŠคํŠธ์˜ ์ƒ‰์ƒ์„ ๋ณ€๊ฒฝ ํ•  ์ˆ˜ ์žˆ๋‹ค.

Text("I'm eemdeeks")
    .foregroundColor(Color.red)

background()

Text์˜ ์Œ์˜์ด๋‚˜ ๋ฐฐ๊ฒฝ์˜ ์ƒ‰์„ ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค๋ฉด background๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

Text("I'm eemdeeks")
    .background(Color.blue)

์ด์™ธ์˜ ๊ฒƒ๋“ค

  • frame() ๋“ฑ๋“ฑ์ด ์žˆ๋‹ค.