티스토리 뷰

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import SwiftUI
 
struct ContentView: View {
    
    @State private var progress: CGFloat = 0
    
    
    var body: some View {
        VStack{
            
            Slider(value: $progress)
                .padding()
            
            ZStack{
                Circle()
                    .stroke(Color.gray.opacity(0.3), lineWidth: 20)
                
                Circle()
                    .trim(from: 0, to: progress)
                    .stroke(style: StrokeStyle(lineWidth: 20, lineCap: .round, lineJoin: .round))
                    .fill(progress == 1 ? Color.green : Color.red)
                    .rotationEffect(.degrees(-90))
                    .animation(.easeInOut)
                
                Text("\(String(format: "%.2f", progress * 100))"+"%")
                    .foregroundColor(progress == 1 ? Color.green : Color.red)
                    .font(.largeTitle)
            }.padding()
            
        }
    }
}
cs

- progress : 진행율 나타냄.

- Slider로 진행율 pickup

- ZStack : Circle두개 겹침

- trim으로 분할원생성 -> stroke (StrokeStyle로 세부 설정) 가 선 모양만 남기고 거름

- fill, rotationEffect, animation

'iOS 개발 > SwiftUI' 카테고리의 다른 글

SwiftUI) json networking  (0) 2022.02.15
SwiftUI) @State, @Binding 예제  (0) 2022.01.31
SwiftUI) ScrollView 예제  (0) 2022.01.30
SwiftUI) TextEditor 예제  (0) 2022.01.30
SwiftUI) Toggle Custom 예제  (0) 2022.01.30
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함