加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React Native中的Google字体

发布时间:2020-12-15 05:04:52 所属栏目:百科 来源:网络整理
导读:我想知道是否可以在我的React Native项目中使用Google字体. 我一直在寻找一些信息,但我没有找到任何东西. 可能吗? 谢谢. P.D.:我知道我可以下载并将其包含在我的项目中. 从这里下载谷歌字体: Github Google Fonts 假设您的字体是Quicksand,您可以在index.
我想知道是否可以在我的React Native项目中使用Google字体.

我一直在寻找一些信息,但我没有找到任何东西.

可能吗?

谢谢.

P.D.:我知道我可以下载并将其包含在我的项目中.

从这里下载谷歌字体: Github Google Fonts

假设您的字体是Quicksand,您可以在index.ios.js中执行以下操作:

import _ from 'lodash';

var OldText = Text;

class NewText extends OldText {
  defaultProps = {
    customFont: false
  }

  render() {
    var props = _.clone(this.props);

    if (this.props.customFont) {
      return super.render();
    }

    if (_.isArray(this.props.style)){
      props.style.push({fontFamily: 'Quicksand-Regular',fontSize: 12});
    } else if (props.style) {
      props.style = [props.style,{fontFamily: 'Quicksand-Regular',fontSize: 12}];
    } else {
      props.style = {fontFamily: 'Quicksand-Regular',fontSize: 12};
    }

    this.props = props;

    return super.render();
  }
}

Object.defineProperty(React,'Text',{value: NewText});

然后在xCo??de in =>中添加字体Build Phases =>复制捆绑资源

然后检查项目Info.plist中是否有以下内容:

<key>UIAppFonts</key>
<array>
    <string>Quicksand-Bold.otf</string>
    <string>Quicksand-BoldItalic.otf</string>
    <string>Quicksand-Italic.otf</string>
    <string>Quicksand-Light.otf</string>
    <string>Quicksand-LightItalic.otf</string>
    <string>Quicksand-Regular.otf</string>
    <string>Quicksand_Dash.otf</string>
</array>

这对我有用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读