SwiftUI:对齐问题、样式表、填充
SwiftUI: Alignment Issues, Style Sheets, Padding
我是堆栈溢出的新手。我想要的是右上角的信息按钮。没有背景,只有白色的图标。我目前在底部有一个黑色背景,左下角有图标。我有按钮工作,但我无法正确定位。有人可以告诉我哪里出错了吗?这是我的代码和当前位置。
控件视图:
import SwiftUI
struct ControlView: View {
@Binding var showInfo: Bool
var body: some View {
ZStack {
HStack{
Spacer()
// Info Button
ControllButton(systemIconName: "info.circle") {
print("Info Button Pressed")
self.showInfo.toggle()
}.sheet(isPresented: $showInfo, content: {
// InfoView
InfoView(showInfo: $showInfo)
})
}
.frame(maxWidth: 500)
.padding()
.background(Color.black.opacity(0.05))
}
Spacer()
}
}
struct ControllButton: View {
let systemIconName: String
let action: () -> Void
var body: some View {
Button(action: {
self.action()
}){
Image(systemName: systemIconName)
.font(.system(size: 35))
.foregroundColor(.white)
.buttonStyle(PlainButtonStyle())
}
.frame(width: 50, height: 50)
}
}
内容视图:
import SwiftUI
import RealityKit
struct ContentView : View {
@State private var isWalkthroughViewShowing = true
@State private var showInfo: Bool = false
var body: some View {
Group{
if isWalkthroughViewShowing{
WalkthroughView(isWalkthroughViewShowing: $isWalkthroughViewShowing)
} else {
ARViewContainer().edgesIgnoringSafeArea(.all)
ControlView(showInfo: $showInfo)
}
}
}
}
截图:
image
首先,欢迎 Jeremy。
您可以简单地使用 .overlay
修饰符:
ARViewContainer().edgesIgnoringSafeArea(.all)
.overlay(ControlView(showInfo: $showInfo).padding(), alignment: .topTrailing)
我是堆栈溢出的新手。我想要的是右上角的信息按钮。没有背景,只有白色的图标。我目前在底部有一个黑色背景,左下角有图标。我有按钮工作,但我无法正确定位。有人可以告诉我哪里出错了吗?这是我的代码和当前位置。
控件视图:
import SwiftUI
struct ControlView: View {
@Binding var showInfo: Bool
var body: some View {
ZStack {
HStack{
Spacer()
// Info Button
ControllButton(systemIconName: "info.circle") {
print("Info Button Pressed")
self.showInfo.toggle()
}.sheet(isPresented: $showInfo, content: {
// InfoView
InfoView(showInfo: $showInfo)
})
}
.frame(maxWidth: 500)
.padding()
.background(Color.black.opacity(0.05))
}
Spacer()
}
}
struct ControllButton: View {
let systemIconName: String
let action: () -> Void
var body: some View {
Button(action: {
self.action()
}){
Image(systemName: systemIconName)
.font(.system(size: 35))
.foregroundColor(.white)
.buttonStyle(PlainButtonStyle())
}
.frame(width: 50, height: 50)
}
}
内容视图:
import SwiftUI
import RealityKit
struct ContentView : View {
@State private var isWalkthroughViewShowing = true
@State private var showInfo: Bool = false
var body: some View {
Group{
if isWalkthroughViewShowing{
WalkthroughView(isWalkthroughViewShowing: $isWalkthroughViewShowing)
} else {
ARViewContainer().edgesIgnoringSafeArea(.all)
ControlView(showInfo: $showInfo)
}
}
}
}
截图: image
首先,欢迎 Jeremy。
您可以简单地使用 .overlay
修饰符:
ARViewContainer().edgesIgnoringSafeArea(.all)
.overlay(ControlView(showInfo: $showInfo).padding(), alignment: .topTrailing)