我正在尝试在Text
上同时添加Image
和Button
,例如:
Button(action: {}) {
Image("gift")
Text("Send")
.padding(.horizontal)
}
.padding()
.foregroundColor(.white)
.background(Color.gray)
.cornerRadius(.infinity)
按钮外观:
但是我要创建这个:
谢谢
答案 0 :(得分:2)
只需将Image
和Text
放在HStack
内…
Button(action: {}) {
HStack {
Image(systemName: "gift")
Text("Send")
}
}
.padding()
.foregroundColor(.white)
.background(Color.gray)
.cornerRadius(.infinity)
答案 1 :(得分:0)
SwiftUI
按钮Text
,Image
和Shadow
的运行正常
Button(action: {
}) {
HStack {
Image(uiImage: UIImage(named: "Login")!)
.renderingMode(.original)
.font(.title)
.foregroundColor(.blue)
Text("Login")
.font(.title)
.foregroundColor(.white)
}
.font(.system(size: 15))
.frame(minWidth: 0, maxWidth: .infinity)
.background(LinearGradient(gradient: Gradient(colors: [Color("DarkGreen"), Color("LightGreen")]), startPoint: .leading, endPoint: .trailing))
.cornerRadius(40)
.frame(width: 200, height: 60, alignment: .center)
.shadow(color: .red, radius: 5, x: 0, y: 0)
}