相信和我一样用惯了 iconfont 的同学们,很难放弃使用它,因为再也不用追着ui给制作小图标了,我们总能找到心仪的小图标, 哈哈哈~ 简直不要太开心! 那么在小程序里,我们要怎么使用iconfont呢?请往下看~
官网:
http://www.iconfont.cn/
第一步:在官网中选好自己心意的图标加入购物车
第二步:添加到项目并下载
第三步:将 iconfont.css 文件中的内容拷贝到 .wxss 文件中
我建议拷贝到app.wxss 中,这样就可以在整个项目中使用 iconfont 图标,当然,如果你只想在局部使用它,那么就拷贝到对应模块的 .wxss 中即可
/**app.wxss**/.container { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; box-sizing: border-box; font-size: 28rpx; color: #333;} /* 引入iconfont */@font-face {font-family: "iconfont"; src: url('iconfont.eot?t=1528182562648'); /* IE9*/ src: url('iconfont.eot?t=1528182562648#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAABHgAAsAAAAAGTQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADMAAABCsP6z7U9TLzIAAAE8AAAARAAAAFZXAkkEY21hcAAAAYAAAADeAAACmANiA7RnbHlmAAACYAAADOMAABEMvNs/W2hlYWQAAA9EAAAAMQAAADYRlfQtaGhlYQAAD3gAAAAgAAAAJAfcA5NobXR4AAAPmAAAABgAAABIR+n//mxvY2EAAA+wAAAAJgAAACYqLiZWbWF4cAAAD9gAAAAfAAAAIAEsAQFuYW1lAAAP+AAAAUUAAAJtPlT+fXBvc3QAABFAAAAAoAAAANnlVXFleJxjYGRgYOBikGPQYWB0cfMJYeBgYGGAAJAMY05meiJQDMoDyrGAaQ4gZoOIAgCKIwNPAHicY2Bk/s84gYGVgYOpk+kMAwNDP4RmfM1gxMjBwMDEwMrMgBUEpLmmMDgwVDwXZm7438AQw9zAMAUozAiSAwAn0gybeJzFkk1Ow0AMhb9pOkkJ5aeq1HbBgiKWrNur5QwciBUn6BlYvxyjPMddgGANtr5I8zLxi2wDFW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UOCg8ywtLkrOlKpFrneHojuXDhJDM2JWt3OjqjK+jfNtk3SQ8cGt8o3vyd3L6N2Sdi5IP5Hqjv9qcssQd5Q/LnnSwLC9af/JkxfiLlV5WZhw5NS3HyEMRWIIVVuoN1pA16g==') format('woff'), url('iconfont.ttf?t=1528182562648') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/ url('iconfont.svg?t=1528182562648#iconfont') format('svg'); /* iOS 4.1- */}.iconfont { font-family:"iconfont" !important; font-size:16px; font-style:normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;}.icon-gouwuche:before { content: "\e600"; }.icon-weibiaoti1:before { content: "\e621"; }.icon-zhongzhijiaoyimima:before { content: "\e626"; }
第四步:修改@font-face
将以上代码拷贝,替换, 如下:
/**app.wxss**/.container { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; box-sizing: border-box; font-size: 28rpx; color: #333;} /* 引入iconfont */@font-face { font-family: 'iconfont'; /* project id 675140 */ src: url('//at.alicdn.com/t/font_675140_d33rycuy1wfxn7b9.eot'); src: url('//at.alicdn.com/t/font_675140_d33rycuy1wfxn7b9.eot?#iefix') format('embedded-opentype'), url('//at.alicdn.com/t/font_675140_d33rycuy1wfxn7b9.woff') format('woff'), url('//at.alicdn.com/t/font_675140_d33rycuy1wfxn7b9.ttf') format('truetype'), url('//at.alicdn.com/t/font_675140_d33rycuy1wfxn7b9.svg#iconfont') format('svg');}.iconfont { font-family:"iconfont" !important; font-size:16px; font-style:normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;}.icon-gouwuche:before { content: "\e600"; }.icon-weibiaoti1:before { content: "\e621"; }.icon-zhongzhijiaoyimima:before { content: "\e626"; }
第五步:使用iconfont
<text class='iconfont icon-zhongzhijiaoyimima'></text>
到这里,你就会使用iconfont了,赶紧去试试吧~