我无法弄清楚如何在SwiftUI中更改按钮的宽度。
我已尝试过以下方法: - 使用 .frame(minWidth: 0, maxWidth: .infinity)。 - 在按钮和导航链接周围使用 Spacer()。 - 在 Text 字段上使用 frame,并在按钮上使用 padding。 - 查看文档,以及在网上搜索到的其他一些内容。但是没有任何方法可以改变按钮的宽度。
NavigationLink(destination: Home(), isActive: self.$isActive) { Text("") }
Button(action: { self.isActive = true }) { LoginBtn() }
struct LoginBtn: View {
var body: some View {
Text("Login")
.fontWeight(.bold)
.padding()
.foregroundColor(Color.white)
.background(Color.orange)
.cornerRadius(5.0)
}
}
我希望按钮可以扩展到与使用的文本字段宽度类似。再次说明,我知道已经有答案发布了,但由于某种原因我无法使我的工作生效。谢谢!