티스토리 뷰

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 myString = "hello world"
    @State private var showPlaceHolder = false
    
    var body: some View {
        VStack{
            VStack{
            Image(systemName: "person")
                .resizable()
                .frame(width: 100, height: 100)
                .clipShape(Circle())
                .overlay(Circle().stroke())
            Text(myString).padding()
            }
            .redacted(reason: showPlaceHolder ? .placeholder : .init())
            
            Button("click me"){
                showPlaceHolder.toggle()
            }
        }
    }
}
 
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
 
cs
- redacted가 Bool변수 showPlaceHolder의 상태에 따라 placeholder를 띄우고 말고를 정함.
- Button은 Bool변수 showPlaceHolder의 상태 조작에 사용됨.(toggle())
- Image와 Button을 포함하는 VStack에게 redacted가 적용되었기 때문에 둘은 동시에 placeholder를 띄우게됨.
- .clipShape가 Image의 frame을 둥글게 잘라줌.
- .overlay(Circle().stroke())가 둥글게 잘린 Image의 틀을 둥근 선으로 감쌈.

 

showPlaceHolder = false
showPlaceHolder = true

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
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
글 보관함