小程序如何设置全局字体按比例缩放?

小程序 文章 2022-03-31 18:00 1049 0 全屏看文

AI助手支持GPT4.0

小程序如何设置全局字体按比例缩放?How does the applet set the global font to be scaled proportionally?

小程序如何设置全局字体按比例缩放?

需求是这样的:用户可以在小程序里面自由调整全局字体的大小,不是统一字号,只是现有的字体按比例缩放,以适应更多的人群

那么问题来了,查阅了小程序的文档好像也没有这种api,求助大神

小程序如何全局动态按比例缩放字体

The requirements are as follows: users can freely adjust the size of the global font in the applet, not the unified font size, but the existing font is scaled to adapt to more people. Then the problem comes. It seems that there is no such API after consulting the applet's documents. Ask the big God applet how to dynamically scale the font globally

回答:

吃鱼先生:

字体使用rem单位,用page-meta组件包裹你的wxml文件,

page-meta组件中设置好root-font-size即可,

root-font-size建议设置到全局stores中,

小程序全局stores推荐:

https://www.npmjs.com/package/mobx-miniprogram-bindings

page-meta文档见:

https://developers.weixin.qq.com/miniprogram/dev/component/page-meta.html

老张:

onShow:function(){this.setData({fontSize:app.globalData.fontSize})}

:这样设置全部都是一个字号了,需要按比例缩放的
拾忆:

没有动态设置字体大小的API,只能自己多写几套样式让用户选择切换,或者根据rpx自动缩放。

:偏偏就遇到这种需求,唉
拾忆:那就提前写好多种风格样式,然后切换吧。
:这样太难维护了

-EOF-

AI助手支持GPT4.0