如果用户点击照片,它将切换到具有以下代码的图形:
import SwiftUI
struct TestView : View {
@State var photo = true
var imagePhoto = "Day-1"
var imageVector = "Dag-1"
var body: some View {
Image(photo ? imagePhoto : imageVector)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 200)
.background(Color.black)
.padding(.leading, 0)
.tapAction {
self.photo.toggle()
}
}
}
如果我想更改SF符号中的图标怎么办?以下代码不起作用。
Image(photo ? systemName: "photo" : systemName: "pencil.circle")
答案 0 :(得分:2)
您使用错误,这是正确的语法:
Image(systemName: photo ? "photo" : "pencil.circle")