基础库版本 >= 3.37.0 支持
动态加载网络字体,文件地址需为下载类型。支持全局生效。
注意:
- 字体文件返回的
contet-type参考 font,格式不正确时会解析失败
- 字体链接必须是
https(iOS不支持http)
参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 | 最低版本 |
| global | boolean | false | 否 | 是否全局生效。设置为true,每个页面都会加载该字体;设置为false,只有当前页面会加载该字体。 | 3.37.0 |
| family | string | | 是 | 定义的字体名称 | 3.37.0 |
| source | string | | 是 | 字体资源的地址。建议格式为 TTF 和 WOFF,WOFF2在低版本的 iOS 上会不兼容。 | 3.37.0 |
| desc | object | | 否 | 可选的字体描述符,native 组件不支持该参数 | 3.37.0 |
| scopes | array | ['webview'] | 否 | 字体作用范围 | 3.37.0 |
| success | function | | 否 | 接口调用成功的回调函数 | 3.37.0 |
| fail | function | | 否 | 接口调用失败的回调函数 | 3.37.0 |
| complete | function | | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 3.37.0 |
object.desc 的结构
| 属性 | 类型 | 默认值 | 必填 | 说明 |
| style | string | normal | 否 | 字体样式,可选值为 normal、italic、oblique |
| weight | string | normal | 否 | 字体粗细,可选值为 normal、bold、100、200..900 |
| variant | string | normal | 否 | 设置小型大写字母的字体显示文本,可选值为 normal、small-cap 、inherit |
object.scopes 数组可选范围
| 值 | 版本 |
| webview | 3.37.0 |
| native | 3.40.0 |
object.success 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
| status | string | 加载字体结果 |
object.fail 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
| status | string | 加载字体结果 |
object.complete 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
| status | string | 加载字体结果 |
示例代码
bl.loadFontFace({
family: 'Bitstream Vera Serif Bold',
source: 'url("https://sungd.github.io/Pacifico.ttf")',
success: res => {
console.log(res.status);
},
fail: err => {
console.log(err.status);
},
complete: info => {
console.log(info.status);
}
})