我正在嘗試將徽標的影像作為按鈕。我是 Swift/SwiftUI 的新手,到目前為止我發現的資源似乎是過時的資訊。我已經加載了影像以查看我可以在其中獲取影像,并且我在我想要的位置創建了一個按鈕,我只想將兩者結合起來。代碼如下。
struct ContentView: View {
var body: some View {
VStack {
Image("logo1024")
.resizable()
.padding()
.frame(width: 120, height: 120)
Group{
Button(action: {
print("tapped!")
}, label: {
Text(" ")
.foregroundColor(.white)
.frame(width: 40, height: 40)
.background(Color.green)
.cornerRadius(15)
.padding()
})
}.frame(maxHeight: .infinity, alignment: .bottom)
}
}
}
uj5u.com熱心網友回復:
只需將影像而不是文本放入按鈕(您需要的所有其他修飾符),例如
Group{
Button(action: {
print("tapped!")
}, label: {
Image("logo1024")
.resizable()
.padding()
.frame(width: 120, height: 120)
.foregroundColor(.white)
.frame(width: 40, height: 40)
.background(Color.green)
.cornerRadius(15)
.padding()
})
}.frame(maxHeight: .infinity, alignment: .bottom)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/487469.html
上一篇:無法使用CSS移動按鈕
