n-icon 图标
内置 599 个矢量字形(字体资产随库发行、离线可用、无 CDN/网络依赖;App 用 ttf、H5/微信用 woff2,均 base64 内嵌),也支持接入自有图标字体(registerIconFont 注册一次,用法与内置零差别),另有 image 图片模式。取主题色调可直接用 custom-class="n-icon--primary"(还有 success / warning / error / info / ink / onfill)。
平台兼容性
| App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 头条小程序 | QQ小程序 |
|---|---|---|---|---|---|---|
| √ | √ | √ | × | × | × | × |
API
属性
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | string | "" | 图标名:内置表名 / registerIconFont 注册表里的名;未命中时 name 原样渲染(可直接传任意字符,如 "¥") |
| mode | "glyph" | "image" | "glyph" | 渲染模式:glyph 字形 / image 图片 |
| size | number | 16 | 图标尺寸(px):字形字号与占位宽高(盒子即 size×size 精确方块),image 模式为宽高 |
| color | string | "" | 字形颜色(image 模式无效);空 = 默认墨色,取主题色用 custom-class 色调类 |
| src | string | "" | 图片地址(image 模式) |
| custom-class | string | "" | 挂到根节点的额外 class(可传 n-icon--primary 等取主题色) |
| custom-style | string | "" | 根节点行内样式(如 "margin-right:4px" 用于和文字排间距) |
主题色调类(custom-class 可用值)
| 类名 | 颜色 |
|---|---|
| n-icon--ink | 默认墨色(text-1,随主题) |
| n-icon--onfill | 填充色上的白 |
| n-icon--primary / --success / --warning / --error / --info | 品牌色 / 成功 / 警示 / 错误 / 信息 |
关联 API(@/uni_modules/new-ui 入口导出)
| 方法 | 说明 |
|---|---|
| registerIconFontJson(json, source?, family?) | iconfont.cn 导出物整包注册(json import 进来直传;family 默认 "app-icons") |
| registerIconFont(family, glyphs, source?) | 注册自有图标字体(合并语义;手写小表 / 追加别名场景) |
| resolveIconGlyph(name) | 名称解析(n-icon 的渲染入口):返回字形与字体族,未命中 null |
| getIconGlyph(name) | 取内置图标字形字符(只查内置表) |
| getIconNames() | 内置全部图标名(图标浏览器场景) |
| glyphsFromIconfontJson(json) | iconfont.cn 导出的 iconfont.json 整包转名称表(免手写) |