我正在尝试设置带有呼叫按钮的导航栏的样式。然而,当滚动时,标准导航栏从大到内联,这使得呼叫按钮不再适合导航栏?有没有办法在滚动时阻止导航栏切换?或者,有没有一种特殊的方法可以让按钮在滚动时保持在导航栏上?任何帮助都将不胜感激!谢谢!
到目前为止,这就是我正在使用的!
.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)
}
})发布于 2021-03-27 05:32:38
如果您使用的是SwiftUI,那么您需要创建一个具有.inline显示模式的NavigationView,这样您就不需要使用.large来滚动显示大标题了。
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的原始请求。
https://stackoverflow.com/questions/66824337
复制相似问题