使用SwiftUI,我正在尝试自定义导航栏。我想实现的大多数事情都设法做到了。剩下的一件事是我想将标题文本稍微向下移动。它离屏幕顶部太近(见图)。知道如何做到吗?
import SwiftUI
extension UIColor {
static let mqPetrol = UIColor(red: 0, green: 114 / 255, blue: 152 / 255, alpha: 1.0)
}
struct LandingPage: View {
@State var score: Int = 0
init() {
let navBarAppearance = UINavigationBar.appearance()
navBarAppearance.titleTextAttributes = [
.foregroundColor: UIColor.mqPetrol,
.font: UIFont(name: "RockwellStd-Bold", size: 50)!]
navBarAppearance.tintColor = UIColor.mqPetrol
navBarAppearance.shadowImage = UIImage()
}
var body: some View {
NavigationView {
NavigationLink(destination: Text("Second View")) {
Text("Hello, World!")
}
.navigationBarTitle("Shizzle", displayMode: .inline)
.navigationBarItems(
leading:
Button(action: {
print("Back button pressed")
}) {
Image(systemName: "arrowshape.turn.up.left")
.resizable()
.frame(width: 24, height: 24)
},
trailing:
Button(action: {
print("Info button was pressed")
}) {
Image(systemName: "info.circle")
.resizable()
.frame(width: 24, height: 24)
}
)
.navigationBarBackButtonHidden(true)
}
}
}
struct LandingPage_Previews: PreviewProvider {
static var previews: some View {
LandingPage()
}
}