23-06-06
struct ContentView: View{
var body: some View{
Button(action:ButtonPressed){
Text("Click me")
}
}
func buttonPressed(){
// 동작할 코드
}
}
struct ContentView: View{
var body: some View{
Button(action: {
//동작할 코드
}) {
Text("Click me")
}
}
}
다음은 Image 뷰를 버튼으로 만드는 경우.
struct ContentView: View{
var body: some View{
Button(action: {
print("hello")
}) {
Image(systemName: "square.and.arrow.down")
}
}
}
struct ContentView: View{
var body: some View{
Text("hello, World!")
.onAppear(perform: {
//뷰가 나타날 때 수행되는 코드
})
.onDisappear(perform: {
//뷰가 사라질 때 수행되는 코드
})
}
}
추후 추가예정
📚 참고도서
[SwiftUI 기반의 iOS 프로그래밍]