微信小程序如何使用自定义SVG矢量图标
在微信小程序中,经常会用到小图标来装饰界面,我们常用的方法就是引用第三方的图标,但会存在收费或者找不到合适的图标,这时候我建议可以自行编写svg图标代码,就可以随心所欲的使用。具体的效果图如下:
那么在微信小程序中,具体怎样引用自定义的图标的呢,大概的步骤我浅浅的分享如下:
1、在Visual Studio Code编辑器或者其他编辑器编写新建一个.svg的文件,编写svg代码,例如:
<?xml version="1.0" encoding="UTF-8"?>
<svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><pathd="M24 33C28.9706 33 33 28.9706 33 24C33 19.0294 28.9706 15 24 15C19.0294 15 15 19.0294 15 24C15 28.9706 19.0294 33 24 33Z"fill="#2F88FF" stroke="#2F88FF" stroke-width="4" />
</svg>
2、点击预览按钮,如果在Visual Studio Code找不到预览的按钮,可以在Visual Studio Code中,使用Ctrl+Shift+X快捷键来打开扩展面板,然后搜索并安装Vscode-svg-previewer扩展,然后选中.svg后缀的文件后,右上角会出现一个按钮,点击该按钮即可进入预览模式,具体操作如下图所示。
3、在浏览器打开https://www.sojson.com/image2base64.html?ivk_sa=1024320u网址,在图片转 BASE64菜单栏,点击【选择文件】按钮,找到并打开文件夹中的dot.svg文件,然后会出现下图圈出的红色方框base64编码。
4、打开微信开发者工具,新建一个小程序项目,并新建一个wxss格式的公用文件,将svg转换后的base64文件根据名称粘贴到此文件中,例如我新建的wxss名称为icon.wxss,具体新建的文件路径根据自己的习惯。在微信小程序项目中的步骤详细代码如下:
- index.wxml文件
<view class="demo-title">微信小程序<text class="icon icon-dot"></text>图标示例</view>
<view class="demo-box"><text class="icon icon-all"></text><text class="icon icon-male"></text><text class="icon icon-photo"></text>
</view>
<view class="demo-box"><text class="icon icon-power"></text><text class="icon icon-aiming"></text><text class="icon icon-more"></text>
</view>
<view class="demo-box"><text class="icon icon-set"></text><text class="icon icon-tool"></text><text class="icon icon-save"></text>
</view>
- index.wxss文件(如果只是局部使用,可以只在此文件中引入公用文件即可,具体引入方法与全局引入方法一样)
page {background-color: #f1f1f1;
}.demo-title {display: flex;flex-direction: row;align-items: center;justify-content: center;margin: 30rpx;font-size: 32rpx;
}.demo-box {display: flex;flex-direction: row;justify-content: space-around;margin: 20rpx;padding: 40rpx 0;background-color: white;border-radius: 20rpx;
}
- icon.wxss全局共用文件
.icon {height: 45rpx;width: 45rpx;background-repeat: no-repeat;background-size: 100%;
}/* 全部 */
.icon-all {background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDQ4IDQ4IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xOCA2SDhDNi44OTU0MyA2IDYgNi44OTU0MyA2IDhWMThDNiAxOS4xMDQ2IDYuODk1NDMgMjAgOCAyMEgxOEMxOS4xMDQ2IDIwIDIwIDE5LjEwNDYgMjAgMThWOEMyMCA2Ljg5NTQzIDE5LjEwNDYgNiAxOCA2WiIgZmlsbD0iIzJGODhGRiIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48cGF0aCBkPSJNMTggMjhIOEM2Ljg5NTQzIDI4IDYgMjguODk1NCA2IDMwVjQwQzYgNDEuMTA0NiA2Ljg5NTQzIDQyIDggNDJIMThDMTkuMTA0NiA0MiAyMCA0MS4xMDQ2IDIwIDQwVjMwQzIwIDI4Ljg5NTQgMTkuMTA0NiAyOCAxOCAyOFoiIGZpbGw9IiMyRjg4RkYiIHN0cm9rZT0iIzMzMyIgc3Ryb2tlLXdpZHRoPSI0IiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PHBhdGggZD0iTTQwIDZIMzBDMjguODk1NCA2IDI4IDYuODk1NDMgMjggOFYxOEMyOCAxOS4xMDQ2ID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SIyNCIgY3k9IjI0IiByPSIzIiBmaWxsPSIjMzMzIi8+PGNpcmNsZSBjeD0iMzYiIGN5PSIyNCIgcj0iMyIgZmlsbD0iIzMzMyIvPjwvc3ZnPg==');
}/* 开关 */
.icon-power {background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDQ4IDQ4IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNC41IDhDMTMuODQwNiA4LjM3NjUyIDEzLjIwNjIgOC43OTEwMyAxMi42IDkuMjQwNTFDMTEuNTYyNSAxMC4wMDk3IDEwLjYwNzQgMTAuODgxNCA5Ljc1IDExLjg0MDJDNi43OTM3NyAxNS4xNDYzIDUgMTkuNDg5MSA1IDI0LjI0NTVDNSAzNC42MDMzIDEzLjUwNjYgNDMgMjQgNDNDMzQuNDkzNCA0MyA0MyAzNC42MDMzIDQzIDI0LjI0NTVDNDMgMTkuNDg5MSA0MS4yMDYyIDE1LjE0NjMgMzguMjUgMTEuODQwMkMzNy4zOTI2IDEwLjg4MTQgMzYuNDM3NSAxMC4wMDk3IDM1LjQgOS4yNDA1MUMzNC43OTM4IDguNzkxMDMgMzQuMTU5NCA4LjM3NjUyIDMzLjUgOCIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjQiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0yNCA0VjI0IiBzdHJva2U9IiMzMzMiIHN0cm9rZS13aWR0aD0iNCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PC9zdmc+');
}/* 男性 */
.icon-male {background-image: url('data:image/svg+xml;base64,PD94bW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pZHRoPSI0IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48cGF0aCBkPSJNMTQgMjZIMzQiIHN0cm9rZT0iI0ZGRiIgc3Ryb2tlLXdpZHRoPSI0IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48cGF0aCBkPSJNMTQgMzRIMjQuMDA4MyIgc3Ryb2tlPSIjRkZGIiBzdHJva2Utd2lkdGg9IjQiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==');
}/* 点 */
.icon-dot {background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDQ4IDQ4IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0yNCAzM0MyOC45NzA2IDMzIDMzIDI4Ljk3MDYgMzMgMjRDMzMgMTkuMDI5NCAyOC45NzA2IDE1IDI0IDE1QzE5LjAyOTQgMTUgMTUgMTkuMDI5NCAxNSAyNEMxNSAyOC45NzA2IDE5LjAyOTQgMzMgMjQgMzNaIiBmaWxsPSIjMzMzIiBzdHJva2U9IiMzMzMiIHN0cm9rZS13aWR0aD0iNCIvPjwvc3ZnPg==');
}
- 在项目pages同级文件夹的app.wxss中引入公用wxss文件,其中文件的路径根据自己新建的位置而定。
@import "./icon.wxss";
上述代码中未用到js代码,对于svg代码的编写,在网上有很多,有兴趣可以自己多学学,正所谓技多不压身。