需求是这样的:用户可以在小程序里面自由调整全局字体的大小,不是统一字号,只是现有的字体按比例缩放,以适应更多的人群
那么问题来了,查阅了小程序的文档好像也没有这种api,求助大神
小程序如何全局动态按比例缩放字体
小程序如何设置全局字体按比例缩放?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
回答:
onShow:function(){this.setData({fontSize:app.globalData.fontSize})}
没有动态设置字体大小的API,只能自己多写几套样式让用户选择切换,或者根据rpx自动缩放。
原文出处:小程序如何设置全局字体按比例缩放?
字体使用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