首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode12静态导航栏

Xcode12静态导航栏
EN

Stack Overflow用户
提问于 2021-03-27 05:08:55
回答 1查看 64关注 0票数 0

我正在尝试设置带有呼叫按钮的导航栏的样式。然而,当滚动时,标准导航栏从大到内联,这使得呼叫按钮不再适合导航栏?有没有办法在滚动时阻止导航栏切换?或者,有没有一种特殊的方法可以让按钮在滚动时保持在导航栏上?任何帮助都将不胜感激!谢谢!

到目前为止,这就是我正在使用的!

代码语言:javascript
复制
.navigationBarTitle("Elevate", displayMode: .large)
        
        .navigationBarItems(trailing:
            HStack
            {
                Button(action: {
                    if let url = NSURL(string: "tel://\(1234567890)"), UIApplication.shared.canOpenURL(url as URL) {
                        UIApplication.shared.openURL(url as URL)
                    }
                    print("Edit button was tapped")})
                {
                    Image(systemName: "phone.fill")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: 30)
                        .padding(.top)
                        .accentColor(.black)
                }
                
                Button(action: {
                        print("Message button was tapped")})
                {
                    Image(systemName: "message.fill")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: 30)
                        .padding(.top)
                        .accentColor(.black)
                }
                
                Button(action: {
                        print("Settings button was tapped")})
                {
                    Image(systemName: "gearshape.fill")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: 30)
                        .padding(.top)
                        .accentColor(.black)
                }
            })
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-27 05:32:38

如果您使用的是SwiftUI,那么您需要创建一个具有.inline显示模式的NavigationView,这样您就不需要使用.large来滚动显示大标题了。

代码语言:javascript
复制
struct ContentView: View {
    var body: some View {
        NavigationView {
            Text("This is a View!")
            .navigationBarTitle("Elevate", displayMode: .inline) //set inline display
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button(action: {
                        if let url = NSURL(string: "tel://\(1234567890)"), UIApplication.shared.canOpenURL(url as URL) {
                            UIApplication.shared.openURL(url as URL)
                        }
                        print("Edit button was tapped")})
                    {
                        Image(systemName: "phone.fill")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 30)
                            .padding(.top)
                            .accentColor(.black)
                    }
                }
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button(action: {
                            print("Message button was tapped")})
                    {
                        Image(systemName: "message.fill")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 30)
                            .padding(.top)
                            .accentColor(.black)
                    }
                }
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button(action: {
                            print("Settings button was tapped")})
                    {
                        Image(systemName: "gearshape.fill")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: 30)
                            .padding(.top)
                            .accentColor(.black)
                    }
                }
            }
        }
    }
}

如下所示:

使用.large而不是.inline:

编辑:显示SwiftUI而不是UIKit -感谢@jnpdx指出了OP的原始请求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66824337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档