演示APP
推荐浏览器扫码安装

用来对颜色进行操作。
创建颜色类
| 名称 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| color | any | 是 | - | 颜色,类型可以是 UTSJSONObject、string、Array<string> 格式的颜色 |
| 类型 |
|---|
| WxColor |
import WxColor from '@/uni_modules/wx-ui/libs/uts/color.uts';
let color = new WxColor('#fff')转换为 rgb 颜色
转换为 hex 颜色
转换为 hsl 颜色
| 名称 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| color | any | 是 | - | 颜色,类型可以是 UTSJSONObject、string、Array<string> 格式的颜色 |
| 类型 |
|---|
| WxColor |
color.rgb() // rgb(255, 255, 255)
color.hex() // #fff
color.hsl() // hsl(0, 0%, 100%)获取字符串格式的颜色
| 类型 |
|---|
| string |
获取数组格式的颜色
| 类型 |
|---|
| Array<number> |
获取Map格式的对象
| 类型 |
|---|
| Map<string, number> |
color.rgb().string() // rgb(255, 255, 255)
color.rgb().array() // [255, 255, 255]
color.rgb().map() // Map<string, number>([ ['r': 255], ['g': 255], ['b': 255] ])检测颜色亮度,返回 0 ~ 1的数值
| 类型 |
|---|
| number |
color.rgb().luminance(); // 1判断颜色是否为暗色
| 类型 |
|---|
| boolean |
color.rgb().isDark(); // false判断颜色是否为亮色
| 类型 |
|---|
| boolean |
color.rgb().isLight(); // true获取两颜色之间的渐变值
| 名称 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| twoColor | string(string.ColorString) | 否 | #fff | 第二个颜色 |
| step | number | 否 | 10 | 获取渐变颜色的个数 |
| 类型 |
|---|
| Array<string> |
color.gradient('#000', 10);
// ["#FFFFFF","#E6E6E6","#CCCCCC","#B3B3B3","#999999","#808080","#666666","#4D4D4D","#333333","#000000"]