uni-app自定义小程序导航栏,适配刘海屏幕。

状态栏和导航栏用统一的背景填充,自定义一个如下导航栏的效果

 

 uni-app中有获取高度的api,如下代码;

<template>
    <view class="content">
        <!-- 背景图片 包含状态栏的标题-->
        <image class="logo" src="背景图片路径" mode=""></image>
        <!-- 状态栏的占位 -->
        <view class="boxAndTop" :style="{height:statusBarHeight+'px'}"></view>
        <!-- 标题栏 -->
        <view class="uni-seleton" :style="{height:titleBarHeight+'px'}">
            <view class="back-btn">
                <view class="back-btn-go" @click="navBack">
                    <image src="返回按钮图片" mode=""></image>
                </view>
                <view class="title" :style="{lineHeight:titleBarHeight+'px'}">标题栏</view>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                statusBarHeight: 0,
                titleBarHeight: 0
            }
        },
        onLoad() {

        //获取状态栏的高度
            let systemInfo = uni.getSystemInfoSync()
            this.statusBarHeight = systemInfo.statusBarHeight
            let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
            this.titleBarHeight = (menuButtonInfo.top - this.statusBarHeight) * 2 + menuButtonInfo.height
        },
        methods: {

            // 返回上一页
            navBack() {
                uni.navigateBack();
            }

        }

    }
</script>

<style lang='scss'>
    .logo {
        width: 100%;
        height: 429rpx;
        position: fixed;
        top: 0;
        right: 0;
        display: block;
    }
    .back-btn {
        z-index: 999;
        font-size: 40upx;
        display: flex;
        justify-content: center;
        width: 100%;
        position: relative;
        .back-btn-go{
            width: 20rpx;
            height: 35rpx;
            position: absolute;
            left: 30rpx;
            top: 50%;
            transform: translateY(-50%);
            image{
                height: 35rpx;
            }
        }
        .title {
            color:#fff;
            font-weight: bolder;
            font-size: 32upx;
        }
    }
</style>

前提是要在pages.json配置

"navigationStyle": "custom",

  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni-app是一个跨平台的开发框架,可以用于开发多个平台的应用程序。在uni-app中,可以通过自定义底部导航栏来实现个性化的界面设计和功能需求。 以下是一种实现自定义底部导航栏的方法: 1. 首先,创建一个自定义组件,用于显示底部导航栏的每个按钮。可以使用`uni-icons`组件来显示图标,并添加相应的点击事件。 ```vue <template> <view> <view class="tabbar"> <view class="tabbar-item" @click="navigateTo('home')"> <uni-icons type="home"></uni-icons> <text>首页</text> </view> <view class="tabbar-item" @click="navigateTo('discover')"> <uni-icons type="discover"></uni-icons> <text>发现</text> </view> <view class="tabbar-item" @click="navigateTo('mine')"> <uni-icons type="mine"></uni-icons> <text>我的</text> </view> </view> </view> </template> <script> export default { methods: { navigateTo(page) { uni.navigateTo({ url: `/pages/${page}/${page}` }); } } } </script> <style> .tabbar { display: flex; justify-content: space-around; align-items: center; height: 100px; background-color: #f5f5f5; } .tabbar-item { display: flex; flex-direction: column; align-items: center; } </style> ``` 2. 在需要显示底部导航栏的页面中,引入自定义组件,并在页面的底部位置使用该组件。 ```vue <template> <view> <!-- 页面内容 --> </view> <custom-tabbar></custom-tabbar> </template> <script> import CustomTabbar from '@/components/CustomTabbar.vue'; export default { components: { CustomTabbar } } </script> ``` 通过以上步骤,你可以实现一个自定义的底部导航栏,并在不同的页面之间进行切换。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值