iconfont官网:https://www.iconfont.cn
一、官方使用篇:
https://www.iconfont.cn/help/detail?spm=a313x.7781069.1998910419.16&helptype=code
##1. Android使用
android可以直接使用单个icon(svg,png)。也可以直接引入字体应用:
第一步:从iconfont平台选择要使用到的图标,并下载至本地;复制字体文件到项目 assets 目录
第二步:打开从iconfont平台下载下来的文件,并在目录中打开demo.html,找到图标相对应的 HTML 实体字符码;
第三步:打开 res/values/strings.xml,添加 string 值;
<string name="icons">㘅 㖭 㖮 㖯</string>
第四步:打开 activity_main.xml,添加 string 值到 TextView:
<TextView
android:id="../../+id/like"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="../../string/icons" />
第五步:为 TextView 指定文字:
import android.graphics.Typeface;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Typeface iconfont = Typeface.createFromAsset(getAssets(), "iconfont/iconfont.ttf");
TextView textview = (TextView)findViewById(R.id.like);
textview.setTypeface(iconfont);
}
##2. IOS使用
IOS可以直接使用单个icon(svg,png)。也可以直接引入字体应用:
第一步:将您从IconFont平台下载的字体文件(.ttf)添加到工程中;
打开Info.plist文件,增加一个新的Array类型的键,键名设置为UIAppFonts(Fonts provided by application),增加字体的文件名:“iconfont.ttf“
第二步:使用IconFont字体:
UILabel * label = [[UILabel alloc] initWithFrame:self.view.bounds];
UIFont *iconfont = [UIFont fontWithName:@"uxIconFont" size: 34];
label.font = iconfont;
label.text = @"\U00003439 \U000035ad \U000035ae \U000035af \U000035eb \U000035ec";
[self.view addSubview: label];
这里有两个地方注意下:
- 创建 UIFont 使用的是字体名,而不是文件名;
- 文本值为 8 位的 Unicode 字符,我们可以打开 demo.html 查找每个图标所对应的 HTML 实体 Unicode 码,比如: "店" 对应的 HTML 实体 Unicode 码为:0x3439 转换后为:\U00003439 就是将 0x 替换为 \U 中间用 0 填补满长度为 8 个字符
二、实战使用篇
##1.android实战使用
https://blog.csdn.net/AME1314/article/details/89791042
##2.IOS 实战 使用
https://www.jianshu.com/p/0e899abe6bbc
演示demo:https://github.com/chuzhaozhi/iconfontDemo