LoginSignup
3
3

More than 5 years have passed since last update.

[Sencha Touch]アイコンの変更方法

Last updated at Posted at 2014-01-26

はじめに

Sencha Touchのバージョン2.2以降では、アイコン表示にアイコンフォントを使用するようになった。
ここでは、アプリで使用するアイコンの変更方法を説明する。

デフォルトで使えるアイコン

デフォルトテーマではPictosフォントを使用している。

デフォルトではPictosフォントの全アイコンが使用できるようにはなっていない。
デフォルトで使えるアイコンの一覧は公式ドキュメントには載っていないが、以下のファイルの@if $include-default-icons {のところに定義されている。

<アプリフォルダ>/touch/resources/themes/stylesheets/sencha-touch/default/src/_Button.scss

Pictosフォントからアイコンを追加する

例:ハートマークのアイコンをアイコンクラス名"heart"で使用できるようにする

app.scss
@import 'sencha-touch/default';
@import 'sencha-touch/default/all';

//※テーマのインポート後に記述
@include icon('heart');

アイコンクラス名は以下のファイルのicon-character-for-nameという関数に定義されている。

<アプリフォルダ>/touch/resources/themes/stylesheets/sencha-touch/baes/mixins/_Class.scss

上記に定義されているクラス名が気に食わなければ、第1引数に任意のクラス名、第2引数にアイコンフォントの文字コードを指定すれば変更できる。
例:ハートマークのアイコンをアイコンクラス名"like"で使用できるようにする

app.scss
@include icon('like', 'k');

他のアイコンフォントを使用する

例:GenericonsのTwitterアイコンを使用する

  1. Genericonsのホームページからアイコンフォントをダウンロードする。
  2. zipファイルを解凍してfontフォルダ内のフォントファイルを以下の場所にコピーする。
    <アプリフォルダ>/resources/sass/stylesheets/fonts/genericons/
  3. app.scssに以下の記述を追加する。
app.scss
@include icon-font('genericons', inline-font-files(
        'genericons/genericons-regular-webfont.woff', woff, 
        'genericons/genericons-regular-webfont.ttf', truetype,
        'genericons/genericons-regular-webfont.svg', svg
));
@include icon('twitter', '\f202', 'genericons');

\f202はアイコンに対応付けられた文字コードで、Genericonsホームページでアイコンを選択してCopy CSSのリンクをクリックすると表示される。

デフォルトアイコン定義を無効にする

app.scss
//※テーマのインポート前に記述
$include-default-icons: false;

@import 'sencha-touch/default';
@import 'sencha-touch/default/all';

参考

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3