微信小程序自定义字体及自定义图标问题说明

自定义图标及自定义字体,一直是不少小程序开发者的心病,其实本站是不少解决方案的,为了集中起来,方便直接跳过此坑,我特别作了此次针对字体及字体图标的跳坑;php

相关文章:
微信小程序添加并使用外部字体(成功添加到维吾尔语了...
新手跳坑指南《六十七》字体文件没法找到报404错误
在微信小程序中使用字体图标/自定义字体/外部字体css

相关插件:
微信小程序实用组件:使用font-awesome字体,真机可用
微信小程序demo:bootstrap字体样式使用sql

相关帖子:
小程序里面能用阿里字体图标吗
微信小程序中怎么使用字体图标chrome

相关讨论:
Q:小程序开发时可否使用咱们自定义的字体图标。
A:自定义字体是支持的,可是须要使用线上字体,而且存放字体的服务器须要容许跨域。bootstrap

相关讨论一:
字体文件没法加载,确认文件是存在的小程序

 

@font-face {
  font-family: 'Glyphicons Halflings';

  src: url('/assets/fonts/glyphicons-halflings-regular.eot');
  src: url('/assets/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('/assets/fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('/assets/fonts/glyphicons-halflings-regular.woff') format('woff'), url('/assets/fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

 

控制台报错segmentfault

  VM884:2 Failed to load font http://1701630871.debug.open.wei ... flings-regular.woff : the server responded with a status of 404 (HTTP/1.1 404 Not Found)
From server 127.0.0.1

文件确实存在的,其余jpg/png图片文件都没问题
是bug,仍是限制了这些文件类型?微信小程序

字体文件要放在网络上请求。跨域

相关讨论二:
小程序使用字体图标的方法分享:原文连接
1、先到阿里巴巴矢量图标库(http://iconfont.cn/)生成本身的字体图标,并下载下来,找到ttf格式文件
服务器

2、到这个平台https://transfonter.org/,把字体文件转化成base64格式

 

3、在wxss文件中引入

4、在wxml加入字体

 

5、显示效果

相关讨论二:
直接引用不行,本地远程的都不行

相关讨论三:input更改字体无效第一个是textarea 第二个是input 第三个是text 用的是缅文, 已经在app.wxss设置了@font-face 结果发现input没法设置字体

 input 组件是一个 native 组件,字体是系统字体,因此没法设置 font-family;

官方文档有说明

相关讨论四:
小程序里使用 iconfont,font-face的src能使用网络地址吗?

  @font-face {
 font-family: 'fontello'; src: url('http://cdn.example.com/iconfont.ttf') format('truetype'); font-weight: normal; font-style: normal; line-height: 1; }

发现src若是用网络地址就不能在iOS上显示,Android和开发工具上是能够的。src用base64值则都是能够显示的。

iOS要使用https的链接的

相关讨论五:

小程序可使用font-awesome来作icon么?能不能用icon-font来作icon,若是不能话有什么好的方案来作icon?

能够, 字体放入到服务器, 远程地址引用就能够了, 例如:

 

@font-face {font-family: "iconfont";
  src: url('//at.alicdn.com/t/xxx.eot?t=1482899691162'); /* IE9*/
  src: url('//at.alicdn.com/t/xxx.eot?t=1482899691162#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('//at.alicdn.com/t/xxx.woff?t=1482899691162') format('woff'), /* chrome, firefox */
  url('//at.alicdn.com/t/xxx.ttf?t=1482899691162') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
  url('//at.alicdn.com/xxx.svg?t=1482899691162#iconfont') format('svg'); /* iOS 4.1- */
}

 

  转自https://segmentfault.com/a/1190000008518103

相关文章
相关标签/搜索