微信小程序自定义radio和CheckBox的样式

wxml:

<view class='title'>radio单选标签</view>
<radio-group bindchange="radioChange">
<view class='label'>
  <label class="ui-radio {{item.checked==true?'active':''}}" wx:for="{{items}}">
    <radio value="{{item.value}}" checked="{{item.checked}}" />
    <text class="text">{{item.name}}</text>
  </label>
  </view>
</radio-group>

<view class='title'>checkbox多选标签</view>
<checkbox-group bindchange="checkboxChange">
  <view class='label'>
    <label class="ui-radio {{item.checked==true?'active':''}}" wx:for="{{checkboxItems}}">
      <checkbox value="{{item.name}},{{item.id}}" checked="{{item.checked}}" />
      <text class="text">{{item.name}}</text>
    </label>
  </view>
</checkbox-group>

js:

Page({
  data: {
    items: [
      { value: 'USA', name: '美国' },
      { value: 'CHN', name: '中国' },
      { value: 'BRA', name: '巴西' },
      { value: 'JPN', name: '日本' },
      { value: 'ENG', name: '英国' },
      { value: 'FRA', name: '法国' },
    ],

    checkboxItems: [
      { value: 'USA', name: '美国', id: 0 },
      { value: 'CHN', name: '中国', id: 1 },
      { value: 'BRA', name: '巴西', id: 2 },
      { value: 'JPN', name: '日本', id: 3 },
      { value: 'ENG', name: '英国', id: 4 },
      { value: 'FRA', name: '法国', id: 5 },
    ]    
  },

 
  radioChange: function (e) {
    var items = this.data.items;
    for (var i = 0; i < items.length; ++i) {
      items[i].checked = items[i].value == e.detail.value
    }
    console.log(items)

    this.setData({
      items: items
    });
  },


  checkboxChange: function (event) {
    var items = this.data.checkboxItems;
    var id = [];
    //获取标签id
    for (var i = 0; i < event.detail.value.length; i++) {
      var idNum = event.detail.value[i].split(','); 
      id = id.concat(idNum[1])
    }
    for (var y = 0; y < items.length; y++) {
      if (id.indexOf(y + "") != -1) {
        items[y].checked = true;
      } else {
        items[y].checked = false;
      }
    }
    this.setData({
      checkboxItems: items
    });
  }
})

wxss:

.title{
  margin-left: 20rpx;
  margin-top: 50rpx;
}

.ui-radio radio,.ui-radio checkbox {
  display: none;
}

.label{
  margin-left: 10rpx;
  display: flex;
  flex-direction: row;
  flex-wrap:wrap;
}

.ui-radio{
  border: 1px solid #D9D9D9;
  border-radius: 5px;
  width: 160rpx;
  height: 70rpx;
  text-align: center;
  margin: 10rpx 10rpx;
  white-space:nowrap;
  font-size: 14px;
}

.ui-radio.active{
  background-color: #1AAD19;
  color: #fff;
  border-radius: 5px;
  border: 1px solid #1AAD19;
  width: 160rpx;
  height: 70rpx;
  text-align: center;
  margin: 10rpx 10rpx;
  white-space:nowrap;
}

.text{
  color:#000;
  line-height:70rpx;
  font-size: 14px;
}

.ui-radio.active .text{
  color:#fff;
  line-height:70rpx;
  font-size: 14px;
}

效果如图:微信小程序自定义radio和CheckBox的样式