在swiftui中,如何增加按钮的高度? [英] In swiftui, How do I increase the height of a button?
本文介绍了在swiftui中,如何增加按钮的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如您在屏幕快照中所见,按钮的高度无法调整以适应文本大小,从而使其看起来很难看.我怎样才能提高按钮的高度,所以它看起来并不愚蠢.我的问题是,如何增加swiftui中按钮的高度.我正在尝试使我的《我的世界》游戏像游戏一样.
As you can see in the screenshot, the button height does not adjust to fit the text size, making it look ugly. How can I increase the hight of the buttons, so it does not look stupid. My question is, how do I increase the height of buttons in swiftui. I am trying to make the titlescreen of my minecraft like game.
struct ContentView: View {
var body: some View {
GeometryReader { geometry in
VStack (spacing: 8) {
Text("[Name not disclosed]Craft").font(.system(size: geometry.size.width/8))
Button(action: {
}) {
Text("Singleplayer").font(.system(size: geometry.size.width/20))
.frame(minWidth: geometry.size.width/2)
}
Button(action: {
}) {
Text("Multiplayer").font(.system(size: geometry.size.width/20))
.frame(minWidth: geometry.size.width/2)
}
HStack (spacing: 8) {
Button(action: {
}) {
Text("Options").font(.system(size: geometry.size.width/20))
.frame(minWidth: (geometry.size.width/4)-16)
}
Button(action: {
exit(EXIT_SUCCESS);
}) {
Text("Quit Game").font(.system(size: geometry.size.width/20))
.frame(minWidth: (geometry.size.width/4)-16)
}
}
}
}
}
}
推荐答案
您只需要设置PlainButtonStyle
并根据需要绘制即可...
You just need to set PlainButtonStyle
and draw it as you wish...
例如,这是您的按钮之一:
Here is for example one of your button:
Button(action: {
}) {
Text("Singleplayer").font(.system(size: geometry.size.width/20))
.padding()
.background(RoundedRectangle(cornerRadius: 8).fill(Color.blue))
.frame(minWidth: geometry.size.width/2)
}
.buttonStyle(PlainButtonStyle())
这篇关于在swiftui中,如何增加按钮的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文