Git Product home page Git Product logo

Comments (10)

phoenixsky avatar phoenixsky commented on May 18, 2024 4

@jlsky
Weex如何在native中加载本地的字体文件,如iconfont - 个人文章 - SegmentFault

from incubator-weex-ui.

play175 avatar play175 commented on May 18, 2024 2

这是我的使用方法,仅供参考:

定义css

* {
  font-family: "iconfont" !important;
}

加载字体

beforeCreate() {
    var domModule = weex.requireModule('dom');
    //目前支持ttf、woff文件,不支持svg、eot类型,moreItem at http://www.iconfont.cn/
    domModule.addRule('fontFace', {
      'fontFamily': "iconfont",
      'src': "url('//at.alicdn.com/t/font_153151_5zv8k123shziwwmi.ttf')"
    });
  }

然后就可以愉快的使用了:

<text>&#xe715;用户中心</text>

from incubator-weex-ui.

hizhengfu avatar hizhengfu commented on May 18, 2024 1

@play175 我们这也采用类似方案,封装了一个组件来处理图标的问题。目前类似wxc-tab-page组件中的图标是图片,如果使用图标需要自行修改才可以。如果在组件中可以直接支持字体图标,用起来会更方便。

from incubator-weex-ui.

tw93 avatar tw93 commented on May 18, 2024 1

@hizhengfu 我对wxc-tab-page 进行了一次升级,新增自定义nav栏头部 这样就可以使用iconfont了
同时还有一些其他的升级,可以看一下wxc-tab-page的文档哦

from incubator-weex-ui.

jl360cn avatar jl360cn commented on May 18, 2024

问一下,把字体放在android的assets里可以吗?试验了两天,没出来。之间,只要把链接改为网络,就没问题。
domModule.addRule 支不支持从本地读取字体?

from incubator-weex-ui.

tw93 avatar tw93 commented on May 18, 2024

@jlsky 本地可能是路径问题 获取不到的 建议放到cdn 或者直接使用http://iconfont.cn/

from incubator-weex-ui.

jl360cn avatar jl360cn commented on May 18, 2024

真是奇怪了。刚把问题发上来,就发现,字体显示了。
我把字体放在了app的assets目录下。
mydom.addRule('fontFace', {
'fontFamily': "iconfont3",
'src': "url('file://asstes/iconfont2.ttf')"
});
另外说明,用weex playground源码里的android代码,在加载本地js代码时,bundelUrl指向的是 http://your_ip:12580/examples/build/ 而不是js代码所在的assets目录。

from incubator-weex-ui.

jl360cn avatar jl360cn commented on May 18, 2024

重新说明一下,字体在本地还是不成功。此前说的,出来的原因是:我在子组件里引用了网上的字体,主界面上显示了所用的字体,误导了。

from incubator-weex-ui.

tw93 avatar tw93 commented on May 18, 2024

weex iconfont 字体可能第一次出不来 ,可以参考这个优化 https://segmentfault.com/q/1010000009357817

from incubator-weex-ui.

tw93 avatar tw93 commented on May 18, 2024

可以更新weex-ui到最新,目前wxc-tab-bar、wxc-tab-page 已经支持配置iconfont

npm i weex-ui@latest -S

详细设置可见
https://alibaba.github.io/weex-ui/#/cn/packages/wxc-tab-bar/?id=%e6%b3%a81%ef%bc%9a%e4%bd%bf%e7%94%a8-iconfont

from incubator-weex-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.