经验分享

Iconfont图标库Android/IOS使用方法

我的站长站 2020-11-08 人阅读

阿里巴巴图标超详细使用方法可以看下面这篇教程,本篇我的站长站主要分享阿里巴巴图标在Android和IOS上的使用方法。

相关参考

Android使用方法

1、下载IconFont字体图标

2、复制字体文件到项目 assets 目录

3、打开 iconfont 目录中的 demo.html,找到图标相对应的 HTML 实体字符码

4、打开 res/values/strings.xml,添加 string 值

<string name="icons">&#x3605; &#x35ad; &#x35ae; &#x35af;</string>

5、打开 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);
}

iOS使用方法

1、下载iconfont字体图标

2、将字体文件(.tff)添加到工程中

3、打开Info.plist文件,增加一个新的Array类型的键,键名设置为UIAppFonts(Fonts provided by application),增加字体的文件名:iconfont.ttf

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 使用的是字体名,而不是文件名

可以打开 demo.html 查找每个图标所对应的 HTML 实体 Unicode 码