SwiftUI 自定义导航栏

3,216 阅读1分钟

相关Demo

debugcustom title viewcustom title view search
leadingView&trailingViewforegroundhidden bottom line
background imagebackground linearGradientupdate background alpha
intercept back eventignore top area

使用方式举例

struct ForegroundView: View {
    var body: some View {
        WRNavigationBar {
            ListView()
        }
        .title("set foreground")
        .foreground(.white)
        .isBackButtonBlack(false)
        .background(Color.blue)
    }
}

相关方法

apidescription
foreground(_ foreground: Color)foreground
title(_ title: String)标题(titleView is default)
hiddenLine(_ hidden: Bool)隐藏底部线
backButtonImageName(_ named: String)返回按钮图片资源名称
backButtonHidden(_ hidden: Bool)隐藏返回按钮
isBackButtonBlack(_ isBlack: Bool)黑色返回按钮(backButton is default)
ignoringTopArea(_ ignore: Bool)内容忽略导航栏顶部区域
maxWidth(leading: CGFloat = 80, trailing: CGFloat = 80)leadingView 和 trailingView 最大宽度
background(_ background: Background)background(任意视图)
backButtonTapAction(_ tapAction: @escaping WRBlock)拦截返回按钮事件( hasBackButton == true)
debug(_ debug: Bool)debug(开启调试)
navigationBarTitleView<Content: View>(@ViewBuilder titleView: () -> Content)titleView(任意视图)
wrNavigationBarItems<Leading: View, Trailing: View>(leading:xx, trailing:xx)导航栏 leading & trailing 视图
wrNavigationBarItems<Content: View>(@ViewBuilder leading: () -> Content)导航栏 leading 视图
wrNavigationBarItems(trailing: () -> Content)导航栏 trailing 视图

详情地址

github.com/wangrui460/…