当前位置:   article > 正文

macOS SwiftUI 教程之 04侧边栏切换显示或隐藏侧边栏视图_swift 侧边栏

swift 侧边栏

实战需求

可以使用 NSSplitViewController 中的 toggleSidebar () 功能显示或隐藏侧边栏视图。在撰写本文时,SwiftUI 还没有此功能,但希望即将到来的 WWDC 将提供 SwiftUI 解决方案。

运行效果

在这里插入图片描述

实战代码

import SwiftUI

struct Sidebar: View {

    var body: some View {
        List {
            Label("Books", systemImage: "book.closed")
            Label("Tutorials", systemImage: "list.bullet.rectangle")
            Label("Video Tutorials", systemImage: "tv")
            Label("Contacts", systemImage: "mail.stack")
            Label("Search", systemImage: "magnifyingglass")
        }
        .listStyle(SidebarListStyle())
        .toolbar {
            Button(action: toggleSidebar, label: {
                Image(systemName: "sidebar.left").help("Toggle Sidebar
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/777554
推荐阅读
相关标签
  

闽ICP备14008679号