1. 引入样式
@import "./graceUI/graceIcons.css";
// 可以在app.vue 中全局引用
2. 使用语法
<标签 class="grace-icons icon-图标名称"></标签>
3. 支持标签
支持 view text button 能够容纳文本类的标签;
演示代码
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view slot="gBody" class="grace-body">
<view class="grace-grids grace-margin-top">
<view class="grace-grids-items" v-for="(item, index) in icons" :key="index">
<text class="grace-grids-icon grace-icons" :class="'icon-' + item"></text>
<text class="grace-grids-text">{{item}}</text>
</view>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceFlex from "../../graceUI/components/graceFlex.vue";
export default {
data() {
return {
icons : [
'wifi','face','address','tel','voice','photograph','microphone','keyboard',
'share', 'share2', 'share3', 'share', 'shoppingcard', 'position', 'safe', 'eye',
'arrow-left', 'arrow-right', 'arrow-up', 'arrow-down', 'time', 'time2', 'home', 'back',
'star', 'zan', 'comments', 'write', 'weibo', 'weixin', 'qq', 'remove',
'search', 'close' ,'close2', 'close3', 'refresh', 'loading', 'shoucang', 'boy', 'girl',
'kf1', 'kf2', 'kf3', 'help1', 'help2', 'help3', 'img', 'menu', 'article', 'user', 'phone', 'phone2',
'wallet', 'set', 'friend','scancode','scan','gonggao','speaker','quote', 'order', 'logoff', 'pwd'
]
}
},
onLoad:function(){
},
methods:{
},
components:{
gracePage, graceFlex
}
}
</script>
<style>
</style>
weex 模式下加载字体
Weex 提供 DOM.addRule 以加载自定义字体。开发者可以通过指定 font-family加载 iconfont 和 custom font。
开发者可以使用下面的代码加载自定义字体:
const domModule = weex.requireModule('dom')
domModule.addRule('fontFace', {
'fontFamily': "iconfont2",
'src': "url('https://at.alicdn.com/t/font_1469606063_76593.ttf')"
});# addRule(type, contentObject)
@fontFace 协议名称,不可修改。
@fontFamily font-family的名称。
@src 字体地址,url('') 是保留字段,其参数如下:
http. 从HTTP请求加载, e.g. url('http://at.alicdn.com/t/font_1469606063_76593.ttf')
https. 从HTTPS请求加载, e.g. url('https://at.alicdn.com/t/font_1469606063_76593.ttf')
local, Android ONLY. 从assets目录读取, e.g. url('local://foo.ttf'), foo.ttf 是文件名在你的assets目录中.
file. 从本地文件读取, e.g. url('file://storage/emulated/0/Android/data/com.alibaba.weex/cache/http:__at.alicdn.com_t_font_1469606063_76593.ttf')
data. 从base64读取, e.g. url('data:font/truetype;charset=utf-8;base64,AAEAAAALAIAAAwAwR1NVQrD+....'), 上述data字段不全。注意
addRule 方法里的 fontFamily 可以随意取。这个名字不是字体真正的名字。字体真正的名字(font-family),也就是注册到系统中的名字是保存在字体二进制文件中的。你需要确保你使用的字体的真正名字(font-family)足够特殊,否则在向系统注册时可能发生冲突,导致注册失败,你的字符被显示为‘?’。
如果你使用 http://www.iconfont.cn/ 来构建你的 iconfont。确保在项目设置中,设置一个特殊的 font-family 名字。默认是 “iconfont”,但极大可能发生冲突。
演示代码
<template>
<gracePage :customHeader="false">
<!-- 页面主体 -->
<view class="grace-body" slot="gBody">
<text class="grace-title grace-margin-top">当前页面引入字体模式</text>
<view class="grace-grids">
<view class="grace-grids-items">
<text class="grace-grids-icon myicons"></text>
<text class="grace-grids-text">加号</text>
</view>
<view class="grace-grids-items">
<text class="grace-grids-icon myicons"></text>
<text class="grace-grids-text">退格</text>
</view>
<view class="grace-grids-items">
<text class="grace-grids-icon myicons"></text>
<text class="grace-grids-text">居中</text>
</view>
<view class="grace-grids-items">
<text class="grace-grids-icon myicons"></text>
<text class="grace-grids-text">加粗</text>
</view>
</view>
<text class="grace-title grace-margin-top">全局引入模式 [ 在 app.vue 中引入 ]</text>
<view class="grace-grids">
<view class="grace-grids-items">
<text class="grace-grids-icon grace-icons"></text>
<text class="grace-grids-text">加号</text>
</view>
<view class="grace-grids-items">
<text class="grace-grids-icon grace-icons"></text>
<text class="grace-grids-text">退格</text>
</view>
<view class="grace-grids-items">
<text class="grace-grids-icon grace-icons"></text>
<text class="grace-grids-text">居中</text>
</view>
<view class="grace-grids-items">
<text class="grace-grids-icon grace-icons"></text>
<text class="grace-grids-text">加粗</text>
</view>
</view>
<view style="margin-top:50rpx;">
<text class="grace-text-center grace-text-small">全部图标及编码请在 graceUI 付费群下载、查阅</text>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceFlex from "../../graceUI/weexComponents/graceFlex.nvue";
export default {
data() {
return {}
},
//页面单独使用字体演示
beforeCreate : function(){
const dom = weex.requireModule('dom');
dom.addRule('fontFace', {
'fontFamily': "myiconfont",
'src': "url('https://at.alicdn.com/t/font_823462_4k1ixlmrgqb.ttf')"
});
},
components:{
gracePage, graceFlex
}
}
</script>
<style>
.myicons{font-family:myiconfont;}
</style>全部图标及编码请在 graceUI 付费群下载、查阅~
1. 引入样式
@import "./graceUI/graceIcons.wxss";
// 在app.wxss 中全局引用
2. 使用语法
<标签 class="grace-icons icon-图标名称"></标签>
3. 支持标签
支持 view text button 能够容纳文本类的标签;
演示代码
.wxml
<view class="grace-margin">
<view class="grace-grids" style="margin-top:20px;">
<view class="grace-grids-items" wx:for="{{icons}}" wx:key="index">
<text class=" grace-grids-icon grace-icons {{'icon-' + item}}"></text>
<text class="grace-grids-text">{{item}}</text>
</view>
</view>
<view style="height:20px;"></view>
</view>.js
Page({
data: {
icons : [
'wifi','face','address','tel','voice','photograph','microphone','keyboard',
'share', 'share2', 'share3', 'share', 'shoppingcard', 'position', 'safe', 'eye',
'arrow-left', 'arrow-right', 'arrow-up', 'arrow-down', 'time', 'time2', 'home', 'back',
'star', 'zan', 'comments', 'write', 'weibo', 'weixin', 'qq', 'remove',
'search', 'close' ,'close2', 'close3', 'refresh', 'loading', 'shoucang', 'boy', 'girl',
'kf1', 'kf2', 'kf3', 'help1', 'help2', 'help3', 'img', 'menu', 'article', 'user', 'phone', 'phone2',
'wallet', 'set', 'friend','scancode','scan','gonggao','speaker','quote', 'order', 'logoff', 'pwd'
]
}
})