【发布时间】:2020-11-22 10:01:53
【问题描述】:
我想将两个图标(刷新和设置)上移到与navigationBarTitle 相同的行:
这是我的看法:
struct Games: View {
let diameter: CGFloat = 35.0
var body: some View {
NavigationView {
VStack {
// Create game
HStack {
Image(systemName: "house.fill")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 40, height: 40)
.foregroundColor(.blue)
Spacer()
Button(action: {
}){
Image(systemName: "arrow.clockwise")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 40, height: 40)
.foregroundColor(.gray)
.padding(.horizontal, 30)
}
NavigationLink(destination: Settings()){
Image("settings")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 40, height: 40)
.foregroundColor(.gray)
}
}
HStack{
Spacer()
Button(action: { }){
Text("+ Create game")
.font(.custom("Seravek-Medium", size: 22))
.padding(15)
.background(
RoundedRectangle(cornerRadius: 5)
.fill(Color.blue.opacity(0.1))
)
}
}
.frame(
maxWidth: .infinity,
maxHeight: 80,
alignment: .bottom
)
} // VStack
.navigationTitle("Games").foregroundColor(.blue)
.padding(25)
} // NavigationView
}
}
但似乎 navigationBarTitle 占据了整个宽度。
有什么办法可以解决这个问题吗?
【问题讨论】:
-
看看developer.apple.com/documentation/swiftui/view/… 您可以使用工具栏修饰符将按钮放置在 NavigationBar 中
-
不知道这是可能的。谢谢你