一、自定义单选框
.icon {
width: 30rpx;
height: 30rpx;
padding: 4rpx;
border-radius: 50%;
border: 1rpx solid #c4c4c4;
background-clip: content-box;
&.active {
background-color: #6175F4;
border-color: #6175F4;
}
}
使用
<view class="personal-item dis-flex justify-between align-center">
<text class="text-gray3 f28 fw700">性别</text>
<view class="w70 fw500 dis-flex align-center justify-end">
<view class="inline-flex f28 text-main fw500 ml40 align-center" @tap.stop="gender = 0">
<view class="icon" :class="{'active': gender==0}"></view>
<text class="ml10 f28">先生</text>
</view>
<view class="inline-flex f28 text-main fw500 ml40 align-center" @tap.stop="gender = 1">
<view class="icon" :class="{'active': gender==1}"></view>
<text class="ml10 f28">女士</text>
</view>
</view>
</view>
</view>
二、自定义开关选择器
.label-swith{
width: 106rpx;
height: 41rpx;
background: #F1F1F1;
border-radius: 21rpx;
position: relative;
.on-off{
width: 35rpx;
height: 35rpx;
background: #FFFFFF;
border: 1px solid #E9E9E9;
border-radius: 50%;
position: absolute;
top: 3rpx;
left: 4rpx;
right: 0;
bottom: 0;
transition-duration: .2s;
transition-timing-function: ease;
transition-property: all;
transform: translateX(0%);
&.active {
position: absolute;
background: #6477F4;
border: 2rpx solid #FFFFFF;
right: 4rpx;
opacity: 0;
opacity: 1;
transform: translateX(170%);
}
}
}
使用
<view class="label-swith" @click="switchChange">
<view class="on-off" :class="{active:show}"></view>
</view>
show: false, // 开关
switchChange() {
this.show=!this.show
},
三、修改复选框样式
checkbox.round .wx-checkbox-input {
border-radius: 50%;/* 圆角 */
width: 26rpx;
height: 26rpx;
}
/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */
checkbox.round .wx-checkbox-input.wx-checkbox-input-checked{
background: $colorPrimary;
border-color: $colorPrimary;
}
/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */
checkbox.round .wx-checkbox-input.wx-checkbox-input-checked::before{
border-radius: 50%; /* 圆角 */
width: 26rpx; /* 选中后对勾大小,不要超过背景的尺寸 */
height: 26rpx; /* 选中后对勾大小,不要超过背景的尺寸 */
line-height: 26rpx;
text-align: center;
font-size: 20rpx; /* 对勾大小 26rpx */
color: #fff; /* 对勾颜色 白色 */
background: transparent;
transform: translate(-50%, -50%) scale(1);