【问题标题】:SwiftUI - How to add an Image in the navigationbar with the title?SwiftUI - 如何在导航栏中添加带有标题的图像?
【发布时间】:2022-08-08 01:44:28
【问题描述】:

如何在导航栏的角落添加图像,使标题保持在中心?

像这样的东西 -

    标签: ios image swiftui navigationbar titlebar


    【解决方案1】:

    这是代码:

    struct ContentView: View {
    var body: some View {
                
        let array = ["thing 1", "thing 2", "thing 3", "others"]
        NavigationView{
            
            VStack(alignment: .leading) {
                
                ScrollView(.vertical){
                    
                        ForEach(array, id: \.self) { item in
                                Text(item).font(.title).padding()
                        }
                    }
                
                Spacer()
            }
            .navigationBarTitleDisplayMode(.inline)
                    .toolbar {
                        ToolbarItem(placement: .principal) {
                                Text("Title")
                                    .font(.title)
                        }
                        
                        ToolbarItem(placement: .navigationBarTrailing) {
                                Image(Constants.logoImage).resizable()
                                    .scaledToFit()
                                    .frame(width: 100, height: 50, alignment: .trailing)
                            }
                        }
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-11-11
      • 2020-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多