美文网首页
RN根据产品要求,需要实现用户设置字体大小来展示前端页面;

RN根据产品要求,需要实现用户设置字体大小来展示前端页面;

作者: b0a4e16b967c | 来源:发表于2019-02-18 16:29 被阅读0次

1.定义一个font.js

const appSize = {
 themes1: { font12: 12, font14: 14, font24: 24, },
themes2: { font12: 22, font14: 24, font24: 34, },
themes3: { font12: 32, font14: 44, font24: 54, },
} export default appSize; 

2.在需要用到的页面引用

import themes from "../common/font";

3.设置字体大小时存入stroage里面,并在componentWillMount中判断;例如:(我采用了本地存储的方法,大家可以采用自己定义的方法)

const fontType = new DataRepository().fetchLocalRepository('sizeFont');
fontType.then(res=> {
  if (res) {
    this.setState({ fontThemes: res })
  }
})

4.用的时候直接用

<Text style = {[styles.listText,
              {fontSize: themes[this.state.fontThemes]['font12']}
]} >
{info.item.title}
</Text>

相关文章

网友评论

      本文标题:RN根据产品要求,需要实现用户设置字体大小来展示前端页面;

      本文链接:https://www.haomeiwen.com/subject/zytzeqtx.html