魔改switch样式
- 游戏开发
- 2025-09-12 09:21:01

大人世道变了,现在ui图都不按照框架来画,简直难为前端马农
默认switch是这样得
UI设计稿是这样的
你难道要我受挫组件,哈哈,这个可以有但没必要
直接魔改switch
代码Html
<switch :checked="1 === isDefault" color="#BB0015" @change="switch1Change" />JS
const switch1Change = (e) => { isDefault.value = e.detail.value ? 1 : 0 }CSS(这个比较重要,需要穿透,不然不生效)
::v-deep .uni-switch-input { border: none; border-radius: 0; // background: red; width: 112upx; height: 54upx; transform: scaleX(-1); &::before { border-radius: 0; background: #dfdfdf; height: 54upx; width: 54upx; } &::after { height: 54upx; width: 54upx; border-radius: 0; } } ::v-deep .uni-switch-input.uni-switch-input-checked:after{ transform: translateX(58upx); }成品:
2025/3/4已知问题,当页面尺寸调整时会变形,例如下图(现已修复)
2025/3/4更新:现在页面尺寸变化也不会影响按钮
魔改switch样式由讯客互联游戏开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“魔改switch样式”