ui-app使用iconfont

336 阅读1分钟

1、单色icon,可以设置font-size

选择 Unicode 复制代码

image.png

本地新建iconfont.css文件,将复制的代码到文件中加上https

image.png

将font class的代码下载解压 image.png

image.png 将解压的confront.css文件的代码copy到自己项目中,删除@font-face部分,修改一下font-size(不然小程序中组件使用icon设置大小不生效)

image.png 最后在App.vue中引入css

<style>
	@import '@/assets/iconfont.css';
</style>

现在就可以在组件中使用了,并且可以设置颜色,font-size

<view class="iconfont" class="iconName"></view>

2、多色icon

使用工具iconfont-tools

先安装工具

npm i -g iconfont-tools

image.png

复制代码链接,在项目中运行,一直确认就可以了,都是一些设置项

iconfont-tools --from 复制的链接 --to ./src/assets

可以看到在项目下生成了iconfont-weapp目录,可以查看iconfont-weapp-icon.css中的代码

image.png 在App.vue中引入

@import '@/assets/iconfont-weapp/iconfont-weapp-icon.css';

使用icon

<view class="t-icon" class="iconName"></view>

icon的background样式需要重新覆盖,因为background-repeat、background-position被后面的icon样式重置了