一、iconfont素材网

  • 进入iconfont素材网
  • 挑选想要的素材,加入购物车
  • 点击右上角购物车图标,将图标添加至项目

微信小程序开发笔记 进阶篇④——基于iconfont快速实现icon图标显示-LMLPHP

微信小程序开发笔记 进阶篇④——基于iconfont快速实现icon图标显示-LMLPHP

二、iconfont项目设置

  • 项目设置,勾选base64
  • 生成代码,下载至本地
  • 有用的是iconfont.css

微信小程序开发笔记 进阶篇④——基于iconfont快速实现icon图标显示-LMLPHP
微信小程序开发笔记 进阶篇④——基于iconfont快速实现icon图标显示-LMLPHP
微信小程序开发笔记 进阶篇④——基于iconfont快速实现icon图标显示-LMLPHP

三、微信小程序项目配置

  • iconfont.wxss就是iconfont.cn网站下载的iconfont.css改下后缀即可
  • 关键代码在于
    • <text class="icon-alipay iconfont icon"></text>
    • 其中icon-alipayiconfont.css.icon-fb:before { content: "\e65d";}对应
    • "\e65d"对应在@font-face中的base64 data中

微信小程序开发笔记 进阶篇④——基于iconfont快速实现icon图标显示-LMLPHP

四、全部源码

icon.wxml

<view class="icon_lists demo__list">
  <view class="icon_card">
    <text class="icon-fb iconfont icon"></text>
    <view class="name">fb</view>
  </view>
  <view class="icon_card">
    <text class="icon-github iconfont icon"></text>
    <view class="name">github</view>
  </view>
  <view class="icon_card">
    <text class="icon-twitter iconfont icon"></text>
    <view class="name">twitter</view>
  </view>
  <view class="icon_card">
    <text class="icon-applets iconfont icon"></text>
    <view class="name">applets</view>
  </view>
  <view class="icon_card">
    <text class="icon-alipay iconfont icon"></text>
    <view class="name">alipay</view>
  </view>
  <view class="icon_card">
    <text class="icon-taobao iconfont icon"></text>
    <view class="name">taobao</view>
  </view>
</view>

icon.wxss

@import 'iconfont.wxss';

.icon_lists {
  /* width: 100% !important; */
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  margin: 20rpx;
}

.icon_card {
  /* flex: 0 0 25%; */
  width: 220rpx;
  text-align: center;
  margin-bottom: 30rpx;
}

.name {
  font-size: 30rpx;
  color: #999;
}

.icon {
  display: block;
  height: 100rpx;
  line-height: 100rpx;
  font-size: 100rpx;
  margin: 10rpx;
  color: #333;
}

iconfont.wxss

@font-face {
  font-family: "iconfont"; /* Project id 3579669 */
  src:
       url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAbcAAsAAAAADRAAAAaQAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHFQGYACDPgqMdIpfATYCJAMcCxAABCAFhGcHWxsoC8gOJTWRwADQoQpCPPy39nrfzOzup6RECggdECpAXRWQLcvK1khWilzQtcf/Idy0S+tJ65HWs36gZh4mhoTU4UNaNod/TzdHJ1qfiSFvIv9zqZyx7CLwsy0uc2xbNj0Wjx1Y1uieQMV6X4nKtZapgDWQXd0CueAX7iPQsUUJl0M1TV3A76mUHwJh3FjDQVoZT3tZKfASjUoLNbQ0Ne3eIj6AivTS5T7ehx8f07aFF0mVWSc5d79aAS5/tuAz1lX3/wj5F184XQOZn1AhY8PGzHG/3XmPayzfECo7dfludgBqTApp7N5n7P99JlcoIZzWWeshnmRF+8OriZql7IFwTV+7YCKXQzC2kA+XsUXgkBlbzKEwpuRQMcaqXFRcoxoEJW1U/wRhhzLdDIH9fNV8TFKDJWAL0FDMJ7BbjkDdqzA0SpgRJDqv4qaAju7N0W47g+i6bIhAOxC9xPkGlutsXQYTAekTJm/F7rvkhPQVx2gTNUZRN4UqEz5xl7KlXwYj9gt3ROOiqQgDOgYLZ8O2nMVxwWA0Yphxmn0l65kTowTRrTPgDgekdzpH7Xbt8cuRoWIHnRBi2R1vNIhNhu3dTiqCBQNmvSASUaerxnR3RHecjeecqVsXrDUT+wizgI6ZfPtWSD/3WPHEhEBv9gQaGOq+fqZ/KjwGacRmExyO+WoQROfVY92TShPkujhfN8wVBil0wxWjUOiRrxqjTqNjlH0zVIDhV+KJi0ehrYfO3bpx44Qo3yjaF34o2kz4QJeM79pHzZOT8sUNuuHj4ZD9Sfl36u3dWxWM0zC2AuG/3pv0Xdmu/PEbsZP3SokJMe7IOUmNh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Cx5XwPV7XqpBXcoyUZxSkbCnZK1cNKR0NH6LtYNjhASlXFaMZTtOLCJmeklbM1DJDDDfGBs0Im8HzSlLJqQbJGv5izMCAilRzqj5Gzqf08Ly6IDVVWbchRa4aBJU4DCneZ1YgySzl7iWnMkTZmc9/vg4M1rABUhwlhrZzNKyAoCelS5FGgalVDlG13Ei9xghWBp7YlUhXzpH0IFKNyIN8QEiqkNT18T4MueZM0TMgrlYg1e6kpFWmLK8evJOV7ru21pomUuQoUUUdTeCZ0n2ZB9vL9wzLPHltL88znKdUrR5geI2HdKBXLV3qwUtVMscAAA==') format('woff2'),
       url('iconfont.woff?t=1660113936513') format('woff'),
       url('iconfont.ttf?t=1660113936513') format('truetype');
}

.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-fb:before {
  content: "\e65d";
}

.icon-github:before {
  content: "\e65e";
}

.icon-twitter:before {
  content: "\e65f";
}

.icon-applets:before {
  content: "\e660";
}

.icon-alipay:before {
  content: "\e666";
}

.icon-taobao:before {
  content: "\e667";
}

觉得好,就一键三连呗(点赞+收藏+关注)

08-11 08:30