uniapp自定义选项卡

<view class="tab-control">
                <view class="tab-control-box">
                    <view class="tab-control-box-top">
                        <view class="tab-control-item" 
                         v-for="(item, index) in tabData"
                            :key="item.type" 
                            :class="{'active-tab': index == activeIndex}"
                            @click="activeIndex = index"
                            >
                            {{ item.name }}
                        </view>
                    </view>
                </view>
            </view>

样式

.issue-main {
            .tab-control {
                background: #FC5041;
                padding: 20rpx;
                height: 360rpx;
                background: linear-gradient(-30deg, transparent 50rpx, #FC5041 0) right,
                                        linear-gradient( 30deg, transparent 50rpx, #FC5041 0) left;
                background-size: 50% 100%;
                background-repeat: no-repeat;
                .tab-control-box {
                    width: 100%;
                    height: 420rpx;
                    background: #FFFFFF;
                    border-radius: 20rpx 20rpx 20rpx 20rpx;
                    .tab-control-box-top {
                        width: 100%;
                        display: flex;
                        background: #FD7367;
                        color: #FFFFFF;
                        border-radius: 20rpx 20rpx 0rpx 0rpx;
                        position: relative;
                        z-index: 1;
                        .tab-control-item {
                            width: 25%;
                            text-align: center;
                            height: 80rpx;
                            line-height: 80rpx;
                        }
                    }
                }
            }
        }
        .active-tab {
            background: #fff;
            color: #FC5041;
            font-weight: bold;
            border-radius: 20rpx 20rpx 0rpx 0rpx;
            height: 80rpx !important;
            line-height: 100rpx !important;
            transform: translateY(-10rpx);
            &::before {
                content: '';
                position: absolute;
                bottom: -20rpx;
                left: 0;
                width: 100%;
                height: 20rpx;
                background: inherit; /* 继承父元素背景 */
                z-index: -1;
            }
        }

### 创建弧形选项卡UniApp 中创建弧形选项卡可以通过自定义组件并利用 CSS 和 SVG 来实现复杂形状的效果。对于希望获得更美观界面设计的应用开发者来说,这种方法提供了灵活性。 #### 使用 Canvas 或者 SVG 实现圆角效果 为了构建具有弧度的 TabBar,在 HTML 结构上可以采用 `view` 容器来放置各个标签项,并通过设置背景图片的方式引入由 SVG 制作好的圆形路径作为底部装饰[^1]: ```html <template> <view class="arc-tabbar"> <!-- 底部导航栏 --> <view class="tab-item" v-for="(item, index) in items" :key="index"></view> <!-- 弧线部分 --> <image src="/static/your-arc-shape.svg"/> </view> </template> <style scoped> .arc-tabbar { position: relative; } .tab-item { flex: 1; } </style> ``` #### 动态计算弧度与定位 为了让弧形更加贴合屏幕宽度变化以及不同设备分辨率下的显示需求,可以在 JavaScript 中动态调整样式属性值。这涉及到根据窗口尺寸重新渲染图形元素的位置和大小: ```javascript export default { data() { return { windowWidth: uni.getSystemInfoSync().windowWidth, arcRadius: this.windowWidth / 8 // 假设半径为屏幕宽八分之一 }; }, mounted() { const query = uni.createSelectorQuery().in(this); query.select('.arc-tabbar').boundingClientRect(data => { console.log('TabBar width:', data.width); }).exec(); } }; ``` #### 自定义插件库 如果项目中有多个页面都需要类似的交互体验,则考虑封装成独立的小部件以便重复使用会是一个不错的选择。此外也可以寻找第三方 UI 框架提供的解决方案,它们往往已经包含了丰富的视觉效果支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值