ios - 在 SwiftUI 中向按钮添加文本和图像

标签 ios swiftui

我正在尝试在 Button 上添加 TextImage,如下所示:

Button(action: {}) {
        Image("gift")
        Text("Send")
            .padding(.horizontal)
    }
    .padding()
    .foregroundColor(.white)
    .background(Color.gray)
    .cornerRadius(.infinity)

按钮外观:

enter image description here

但我想创建这个:

enter image description here

谢谢

最佳答案

只需将ImageText放入HStack...

Button(action: {}) {
    HStack {
        Image(systemName: "gift")
        Text("Send")
    }
}
.padding()
.foregroundColor(.white)
.background(Color.gray)
.cornerRadius(.infinity)

enter image description here

关于ios - 在 SwiftUI 中向按钮添加文本和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58048831/

相关文章:

ios - Swift:使用 NSOperation 保留循环

ios - 使用 SwiftUI 添加谷歌登录

ios - SwiftUI:在 View 之间传递 ObservableObject 时,表达式类型在没有更多上下文的情况下不明确

ios - 错误: Use of undeclared type BindableObject

ios - UIView 作为@EnvironmentObject 的订阅者

ios - 如何复制 ABNewPersonViewController 布局

ios - RequestImage 的结果处理程序调用了两次

objective-c - 如何设置先前创建的 NSMutableString 的文本?

ios - 更改按钮 anchor SwiftUI

ios - 延迟出列可重复使用的单元格