微信小程序-UI控件的使用(5)

本文介绍了微信小程序中常用的UI控件,包括Icon图标的显示,Mask遮罩层的实现,Toast提示的用法,Progress条的展示,以及Checkbox复选框和Form表单、Picker选择器的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、icon图标的使用

icon.wxml

<block wx:for-items="{{iconSize}}">
  <icon  type="{{item.type}}" size="{{item.size}}" color="{{item.color}}" />
</block>

icon.js:

Page({
  data: {
    iconNums:[{
        'type':'success',
        'size':'20',
        'color':'red'
    },
    {
        'type':'info',
        'size':'20',
        'color':'yellow'
    },{
        'type':'warn',
        'size':'30',
        'color':'green'
    },{
        'type':'safe_success',
        'size':'40',
        'color':'blue'
    }]
  }
})

效果图:
这里写图片描述

2、mask
mask.wxml

<mask hidden="{{hidden1}}" bindtap="mask1" hover-style="none" />
        <button type="default" bindtap="tap1">点击弹出默认mask</button>

mask.js

Page({
  data: {
    'hidden1':true
  },
  mask1:function(){
     this.setData({'hidden1':true})
  },
  tap1:function(){
     this.setData({'hidden1':false})
  }
})

3、toast

<toast hidden="{{toast3Hidden}}" icon="warn" duration="3000" bindchange="toast3Change">

icon:图标
duration :显示时间
这里写图片描述

4、progress

<progress percent="20" show-info/>
<progress percent="40" active/>
<progress percent="60" stroke-width="10"/>
<progress percent="80" color="#10AEFF"/>

这里写图片描述

5、checkbox

<checkbox-group bindchange="checkboxChange">
                <label class="checkbox" wx:for-items="{{items}}">
                    <checkbox value="{{item.name}}" checked="{{item.checked}}"/>{{item.value}}
                </label>
            </checkbox-group>

这里写图片描述

6、form

<form class="page__bd" catchsubmit="formSubmit" catchreset="formReset">
        <view class="section section_gap">
            <view class="section__title">switch</view>
            <switch name="switch"/>
        </view>
        <view class="section section_gap">
            <view class="section__title">slider</view>
            <slider name="slider" show-value ></slider>
        </view>

        <view class="section">
            <view class="section__title">input</view>
            <input name="input" placeholder="please input here" />
        </view>
        <view class="section section_gap">
            <view class="section__title">radio</view>
            <radio-group name="radio-group">
                <label><radio value="radio1"/>radio1</label>
                <label><radio value="radio2"/>radio2</label>
            </radio-group>
        </view>
        <view class="section section_gap">
            <view class="section__title">checkbox</view>
            <checkbox-group name="checkbox">
                <label><checkbox value="checkbox1"/>checkbox1</label>
                <label><checkbox value="checkbox2"/>checkbox2</label>
            </checkbox-group>
        </view>
        <view class="btn-area">
            <button formType="submit">Submit</button>
            <button formType="reset">Reset</button>
        </view>
    </form>

7、picker

 <view class="page__bd">
        <view class="section">
            <view class="section__title">地区选择器</view>
            <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
                <view class="picker">
                    当前选择:{{array[index]}}
                </view>
            </picker>
        </view>
        <view class="section">
            <view class="section__title">时间选择器</view>
            <picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
                <view class="picker">
                    当前选择: {{time}}
                </view>
            </picker>
        </view>

        <view class="section">
            <view class="section__title">日期选择器</view>
            <picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
                <view class="picker">
                    当前选择: {{date}}
                </view>
            </picker>
        </view>
    </view>

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值