search
HomeWeChat AppletMini Program DevelopmentUse vector fonts to customize applet icon component icons

Mini Program Development Tutorial column introduces how to customize the mini program icon component icon.

Use vector fonts to customize applet icon component icons

A question

The icon component in the WeChat applet has only 9 types: success, success_no_circle, info, warn, waiting, cancel, download, search, clear. For details, please refer to the official documentation of the icon component.

An idea

We often hope to expand the icons of the icon component without being limited by the above 9 icons. This involves how to customize the icon. There are many ways to customize icons, such as using pictures, sprites, CSS style drawing, SVG vector files, etc. This article focuses on how to use vector fonts to customize the icon component icon of the applet.

A concept

What is a vector font?

Fonts include bitmap fonts and vector fonts. Vector fonts are currently widely used and are divided into three categories: Adobe's Type1, TrueType led by Apple and Microsoft, and OpenType, an open source font co-led by Adobe, Apple, and Microsoft. For vector fonts, each Unicode is an encoding index, and the description information for each character is a geometric vector drawing description information. Vector fonts are drawn in real time, so they can be filled with any color in real time and scale infinitely without aliasing.

To use vector fonts, you need to refer to a very useful website: Iconfont-Alibaba Vector Icon Library. This website not only provides icon downloads, but also provides the generation and download of custom vector icons. Next, I will combine rich screenshots to see step by step how to use vector fonts to customize the applet icon component icon.

A practice

Get vector icons

Open the Iconfont-Alibaba vector icon library website, its homepage is as shown below: Use vector fonts to customize applet icon component icons

Because here we I don't care what the icon looks like, I only care about how to customize the icon component icon step by step from vector icon generation to WeChat applet code. So we directly select the first icon collection and click it as shown below.

QH 徐小花图标库

Then click on the first icon library, the details of which are as follows. Here we put the mouse on the third icon - the coffee bean icon, and three buttons will appear, namely add to shopping cart, favorite, and download. We need to click on the add to cart button.

QH 徐小花的茶与咖啡图标库

At this time, the shopping in the upper right corner will have a red corner mark. Click the button in the upper right corner to display the following interface.

Use vector fonts to customize applet icon component icons

Then we click the "Add to Project" button and the following interface will pop up. If there is no project, create a new one. If there is one, just choose an interface you think is suitable. Here I created a new Test project in advance and selected the Test project directly.

Use vector fonts to customize applet icon component icons

After adding a project, the web page will automatically jump to the project details interface. This interface contains the icons just added.

Use vector fonts to customize applet icon component icons

At this time, when we click the "View Online Link" button in the middle, a series of codes will be generated and displayed in the middle of the web page. At this point our task at iconfont.cn has been completed, and we have obtained the icon remote link and Unicode value we want. The code just generated is the remote link of the icon, and the words under the coffee bean icon are the Unicode values ​​corresponding to the icon. These two contents will be used when writing the WeChat applet code below.

Use vector fonts to customize applet icon component icons

Writing code for WeChat applet

Writing code for WeChat applet is relatively easy. First write the WXSS file and link the remote font you just got. Paste it directly into WXSS, then write a custom iconfont style, and finally reference it in the icon component. The code is as follows:

WXSS code

It should be noted that the font-face code copied in iconfont is directly pasted into WXSS. Unicode of the coffee bean picture  Convert the previous to \, and then put it in the content of icon-coffee.

@font-face {  font-family: 'iconfont';  /* project id 1834535 */
  src: url('//at.alicdn.com/t/font_1834535_c5751gpcjt.eot');  src: url('//at.alicdn.com/t/font_1834535_c5751gpcjt.eot?#iefix') format('embedded-opentype'),  url('//at.alicdn.com/t/font_1834535_c5751gpcjt.woff2') format('woff2'),  url('//at.alicdn.com/t/font_1834535_c5751gpcjt.woff') format('woff'),  url('//at.alicdn.com/t/font_1834535_c5751gpcjt.ttf') format('truetype'),  url('//at.alicdn.com/t/font_1834535_c5751gpcjt.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-coffee:before {  content: "\e634";  color: darkgoldenrod;  font-size: 70px;
}复制代码

WXML code

<icon></icon>复制代码

Running effect

Use vector fonts to customize applet icon component icons

At this point, the process of using vector fonts to customize the mini program icon component icon has been introduced. . If you have any questions, welcome to discuss.

Related free learning recommendations: 小program development tutorial

The above is the detailed content of Use vector fonts to customize applet icon component icons. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:juejin. If there is any infringement, please contact admin@php.cn delete
使用Python开发微信小程序使用Python开发微信小程序Jun 17, 2023 pm 06:34 PM

随着移动互联网技术和智能手机的普及,微信成为了人们生活中不可或缺的一个应用。而微信小程序则让人们可以在不需要下载安装应用的情况下,直接使用小程序来解决一些简单的需求。本文将介绍如何使用Python来开发微信小程序。一、准备工作在使用Python开发微信小程序之前,需要安装相关的Python库。这里推荐使用wxpy和itchat这两个库。wxpy是一个微信机器

小程序能用react吗小程序能用react吗Dec 29, 2022 am 11:06 AM

小程序能用react,其使用方法:1、基于“react-reconciler”实现一个渲染器,生成一个DSL;2、创建一个小程序组件,去解析和渲染DSL;3、安装npm,并执行开发者工具中的构建npm;4、在自己的页面中引入包,再利用api即可完成开发。

Java语言中的微信小程序开发介绍Java语言中的微信小程序开发介绍Jun 09, 2023 pm 10:40 PM

微信小程序是一种轻量级的应用程序,可以在微信平台上运行,不需要下载安装,方便快捷。Java语言作为一种广泛应用于企业级应用开发的语言,也可以用于微信小程序的开发。在Java语言中,可以使用SpringBoot框架和第三方工具包来开发微信小程序。下面是一个简单的微信小程序开发过程。创建微信小程序首先,需要在微信公众平台上注册一个小程序。注册成功后,可以获取到

用Python编写简单的聊天程序教程用Python编写简单的聊天程序教程May 08, 2023 pm 06:37 PM

实现思路x01服务端的建立首先,在服务端,使用socket进行消息的接受,每接受一个socket的请求,就开启一个新的线程来管理消息的分发与接受,同时,又存在一个handler来管理所有的线程,从而实现对聊天室的各种功能的处理x02客户端的建立客户端的建立就要比服务端简单多了,客户端的作用只是对消息的发送以及接受,以及按照特定的规则去输入特定的字符从而实现不同的功能的使用,因此,在客户端这里,只需要去使用两个线程,一个是专门用于接受消息,一个是专门用于发送消息的至于为什么不用一个呢,那是因为,只

PHP与小程序的地理位置定位与地图显示PHP与小程序的地理位置定位与地图显示Jul 04, 2023 pm 04:01 PM

PHP与小程序的地理位置定位与地图显示地理位置定位与地图显示在现代科技中已经成为了必备的功能之一。随着移动设备的普及,人们对于定位和地图显示的需求也越来越高。在开发过程中,PHP和小程序是常见的两种技术选择。本文将为大家介绍PHP与小程序中的地理位置定位与地图显示的实现方法,并附上相应的代码示例。一、PHP中的地理位置定位在PHP中,我们可以使用第三方地理位

教你如何在小程序中用公众号模板消息(附详细思路)教你如何在小程序中用公众号模板消息(附详细思路)Nov 04, 2022 pm 04:53 PM

本篇文章给大家带来了关于微信小程序的相关问题,其中主要介绍了如何在小程序中用公众号模板消息,下面一起来看一下,希望对大家有帮助。

小程序中文件上传的PHP实现方法小程序中文件上传的PHP实现方法Jun 02, 2023 am 08:40 AM

随着小程序的广泛应用,越来越多的开发者需要将其与后台服务器进行数据交互,其中最常见的业务场景之一就是上传文件。本文将介绍在小程序中实现文件上传的PHP后台实现方法。一、小程序中的文件上传在小程序中实现文件上传,主要依赖于小程序APIwx.uploadFile()。该API接受一个options对象作为参数,其中包含了要上传的文件路径、需要传递的其他数据以及

苏州健康码的小程序叫什么苏州健康码的小程序叫什么Oct 24, 2022 am 09:47 AM

苏州健康码的小程序叫“苏康码”,它是苏州市疫情防控指挥部指定的通行服务码,疫情防控期间在全市范围内通用,可以作为广大民众日常出行的重要凭证,同时作为防疫人员查验的主要依据;也是省内所有来苏逗苏人员以及在苏工作学习生活,旅游或临时停留人员申报的键康申报数据为基础,结合相关数据比对后动态生成的个人电子健康凭证。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft