iOS/SwiftUI

SwiftUI - Shape

๐ŸฅญMango 2023. 3. 1. 23:16

์•ˆ๋…•ํ•˜์„ธ์š” :D ๋ง๊ณ ์ž…๋‹ˆ๋‹ค๐Ÿฅญ

SwiftUI์˜ Shape์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

shape

SwiftUI์—๋Š” Circle, Rectangle, Ellipse, Capsule ๋“ฑ์˜ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๊ธฐ๋ณธ ๋„ํ˜•๋“ค์„ ์ œ๊ณตํ•œ๋‹ค.

์ด๋“ค์„ ์ด์šฉํ•ด ์›ํ•˜๋Š” ๋ชจ์–‘, ์ƒ‰์„ ์ง€์ •ํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

Circle


 

Circle()
.fill(Color.orange) //์ƒ‰์ƒ์ฑ„์šฐ๊ธฐ
.foregroundColor(.pink) //์ƒ‰์ƒ์ฑ„์šฐ๊ธฐ
.stroke() //ํ…Œ๋‘๋ฆฌ
.stroke(Color.red) //ํ…Œ๋‘๋ฆฌ์ƒ‰์ƒ
.stroke(Color.gray, lineWidth: 30) // ํ…Œ๋‘๋ฆฌ๋‘๊ป˜
.stroke(Color.orange, style: StrokeStyle(lineWidth: 20, lineCap: .butt, dash: [10])) 
// StrokeStyle์„ ํ†ตํ•ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ปค์Šคํ…€ ๊ฐ€๋Šฅ

.trim(from: 0.2, to: 1.0) // ๋„ํ˜•์˜ ๋ถˆ ํ•„์š”ํ•œ ๋ถ€๋ถ„์„ ์ œ๊ฑฐ
.stroke(Color.purple, lineWidth: 50) // ์ด๋Ÿฐ์‹์œผ๋กœ trim๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

Ellipse


 

Ellipse()
    .frame(width: 200, height: 100)

Capsule


Capsule(style: .circular)
    .frame(width: 200, height: 100)
  • ํ…์ŠคํŠธ ๋’ค๋‚˜ ๋ฒ„ํŠผ ๋’ค์— ๋„ฃ๊ณ  ์‹ถ์„ ๋•Œ ์œ ์šฉ

Rectangle


Rectangle()
    .frame(width: 200, height: 100)