代码之家  ›  专栏  ›  技术社区  ›  fransyozef

NativeScript 5 iphone不工作

  •  0
  • fransyozef  · 技术社区  · 6 年前

    https://github.com/NathanWalker/nativescript-ngx-fonticon 包裹。

    - src
    -- assets
    -- fonts
    -- app
    

    fonts文件夹包含我从FontAwesome5网站下载的所有FontFile(eot/svg/ttf/woff/woff2)(fa brands/fa regular/fa solid)

    在我的主scss文件中有一行:

    .fa {
        font-family: FontAwesome, fontawesome-webfont;
    }
    
    .fas {
        font-family: FontAwesome, fa-solid-900;
    }
    

    import { TNSFontIconModule , TNSFontIconService } from 'nativescript-ngx-fonticon';
    TNSFontIconService.debug = true;
    

    和导入:

        TNSFontIconModule.forRoot({
            'fa': './assets/font-awesome.css'
        })
    

    现在在我的HTML中:

    <Label  class="fas" [text]="'fa-bars' | fonticon" color="#2c0239"></Label>
    

    我还修改了我的webpack配置,以复制和监视src/assets/文件夹:

        new CopyWebpackPlugin([
            { from: "assets/**"},
            { from: "fonts/**" },
            { from: "**/*.jpg" },
            { from: "**/*.png" },
        ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
    

    所以当我在iPhone上运行这个程序时,我得到[?]

    2 回复  |  直到 6 年前
        1
  •  1
  •   fransyozef    6 年前

    终于有了:

    .fas {
        font-family: "Font Awesome 5 Free", fa-solid-900;
    }
    

    第一个是iPhone需要的,fa-solid-900是Android需要的。

        2
  •  0
  •   Steven    6 年前

    我就是这样做的因为 that 对我没用。

    我正在使用Nativescript和VueJs

    字体版本:

    您需要使用以下字体:

    fa-regular-400
    fa-brands-400
    fa-solid-900
    

    app>fonts

    将此添加到 app>app.css

    .far {
         font-family: 'Font Awesome 5 Free', fa-regular-400;
         font-size: 40em;
    }
    
    .fab {
        font-family: 'Font Awesome 5 Brands', fa-brands-400;
        font-size: 40em;
    }
    
    .fas {
        font-family: 'Font Awesome 5 Free', fa-solid-900;
        font-size: 40em;
    }
    

    font-size .

    <Label class="fab" :text="'\uf060' | unescape"></Label>
    <Label class="fab" :text="'\uf170' | unescape"></Label>
    <Label class="fab" :text="'\uf36e' | unescape"></Label>
    
    filters: {
               unescape: v => unescape(v)
           }
    

    如果你 search an icon 您将看到unicode。 你得抄下来。

    示例 Unicode for moon is f186

    所以要使用它,你需要 \u{unicode} => \uf186

    它只有在使用属性时才起作用 :text unescape .

    多行按钮

           <Button class="btn">
                <FormattedString>
                    <span class="fas" :text="'\u[ICONCODE]' | unescape" ></span>
                    <span :text="'\n [TEXT]' | unescape" ></span>
                </FormattedString>
            </Button>
    
            filters: {
                       unescape: v => unescape(v)
                   }
    
        3
  •  0
  •   dmstack    6 年前

    要使品牌和Pro FontAwesome5字体在NativeScript Vue中工作,请安装 nativescript-fonticon npm install nativescript-fonticon --save ,如文档中所述 Using Fonticons 从FontAwesome下载网页字体和桌面字体。在目录中 app/fonts .ttf 来自 webfonts .otf 来自 otfs 应用程序/字体 .otf公司 文件以匹配 .ttf文件 文件 enter image description here

    app/assets css web字体下载目录(或所有文件)。 enter image description here

    app.scss (请注意,光和固体在没有 font-weight 正确定义)

    .fa {
      font-family: "Font Awesome 5 Pro", "fa-regular-400";
      font-weight: 400;
    }
    
    .fas {
      font-family: "Font Awesome 5 Pro", "fa-solid-900";
      font-weight: 900;
    }
    
    .fab {
      font-family: "Font Awesome 5 Brands", "fa-brands-400";
      font-weight: 400;
    }
    
    .fal {
      font-family: "Font Awesome 5 Pro", "fa-light-300";
      font-weight: 300;
    }
    

    以下是 main.ts

    import {TNSFontIcon, fonticon} from 'nativescript-fonticon';
    
    TNSFontIcon.debug = true;
    TNSFontIcon.paths = {
      // 'fa': './assets/css/all.min.css',
      // 'fal': './assets/css/all.min.css',
      // 'far': './assets/css/all.min.css',
      // 'fas': './assets/css/all.min.css',
      // 'fab': './assets/css/all.min.css',
      'fa': './assets/css/fontawesome.min.css',
      'fal': './assets/css/light.min.css',
      'far': './assets/css/regular.min.css',
      'fas': './assets/css/solid.min.css',
      'fab': './assets/css/brands.min.css'
    };
    TNSFontIcon.loadCss();
    
    Vue.filter('fonticon', fonticon);
    

    platforms 目录,以确保一切得到正确捆绑,你应该是好去。像这样使用它

      <StackLayout orientation="horizontal" horizontalAlignment="center" verticalAlignment="top">
        <Label class="fab" :text="'fa-git' | fonticon" />
        <Label class="fal" :text="'fa-plus-square' | fonticon" />
        <Label class="fa" :text="'fa-plus-square' | fonticon" />
        <Label class="fas" :text="'fa-plus-square' | fonticon" />
      </StackLayout>
    

    为了让事情变得更简单,有一个插件 Vue-Fonticon 这基本上就是我复制到的下面的代码 app/components/FontIcon.vue

    <template>
      <Label
        :class="type"
        :color="color"
        :fontSize="size"
        :text="name | fonticon"
        :width="size"
        textAlignment="center"
        @tap="$emit('tap')"
      />
    </template>
    
    <script>
      export default {
        name: 'FontIcon',
        props: {
          color: {
            type: String,
            default: 'black'
          },
          name: {
            type: String,
            required: true
          },
          size: {
            type: [String, Number],
            default: 15,
            validation: s => !isNaN(s)
          },
          type: {
            type: String,
            default: 'fa'
          }
        }
      }
    </script>
    

    主要技术支持 添加

    import FontIcon from './components/Utility/FontIcon.vue'
    
    Vue.component(FontIcon.name, FontIcon)
    
    

    把它当作

      <StackLayout orientation="horizontal" horizontalAlignment="center" verticalAlignment="top">
        <FontIcon name="fa-play" size="16" color="red"/>
        <FontIcon name="fa-play" type="fal" size="32" color="green"/>
        <FontIcon name="fa-play" type="fas" size="64" color="blue"/>
        <FontIcon name="fa-git" type="fab" @tap="tapHandler"/>
      </StackLayout>