问题描述
我是一名尝试开发简单的SwiftUI应用程序的网络开发人员,我在询问之前在Google上进行了搜索,但是仍然遇到麻烦。
这是我正在做的一个小应用程序的用户界面。而且我想更改按钮的颜色。
这是我在在线阅读一些示例后尝试使用的代码:
Button(action: {
self.device.setAsDefaultInputDevice()
self.refresh()
}) {
Text("Default")
.padding()
.background(Color.purple) // 2. Change the background color to purple including the padding
.foregroundColor(.white) // 3. Set the foreground/font color to white
.font(.body)
}
当我在文本中添加填充时,一切看起来都错了,我对默认按钮的形状完全满意。 我的最终意图是根据默认值是否为ON交换主/辅助系统颜色。
解决方法
Button(action: {
self.device.setAsDefaultInputDevice()
self.refresh()
}) {
Text("Default")
.padding(.leading)
.padding(.trailing)
.padding(.top,2)
.padding(.bottom,2)
.background(RoundedRectangle(cornerRadius: 4).fill(Color.blue))
}