SenchTouch添加自定义字体图标方法

================================================================================================
==  添加自定义字体图标方法
================================================================================================
首先下载自定义字体图标,可以在线定制后下载(http://icomoon.io/app/#/select)
下载后的字体文件存放到sencha系统字体目录中(如C:\Users\Administrator\AppData\Local\Sencha\Sencha Architect 3.0\extracted\touch23-compile\themes\fonts(ver:3.0) 或者  工程目录/resources/sass/stylesheets/fonts/ (ver:3.1))

在工程中添加scss资源,添加类似如下代码:
@include icon-font('awesome', inline-font-files(
'awesome/awesome.woff', woff,
'awesome/awesome.ttf', truetype,
'awesome/awesome.svg', svg));

@include icon('chevron-right','\f054','awesome');

================================================================================================
== 参考:http://bruno.tavares.me/sencha-touch/adding-custom-font-icons-to-sencha-touch-2-2/
================================================================================================
Adding Custom Font Icons to Sencha Touch 2.2
← prev
next →
Adding Custom Font Icons to Sencha Touch 2.2
In Sencha Touch 2.2 instead of using icons with the -webkit-mask trick, Touch is moving to a more cross-browser solution with icon fonts. You can read more about this at Steve Drucker blog Changes to Sencha Touch 2.2 Theming Part 1: Using Iconography.

As Steve mentions on his blog, Touch SDK ships with the Pictos Font, and it already loads some basic icons for you to use directly on buttons with iconCls.

{
xtype: 'button',
iconCls: 'home'
}
If you want to define more icons from the same Pictos fonts, you just have to use the mixin icon():

@include icon('network');

{
xtype: 'button',
iconCls: 'network',
iconAlign: 'top',
text: 'Net'
}
Touch Theming Layer already has a big object on SASS mapping keys into characters. So when you inform the key “network”, the theme knows that it has to use the key “J”.

Adding Custom Icons

To add more icons you’ll need to generate your own font! You might be question yourself – How do I create a new font? Sounds complicated but it’s fairly easy.

There’s a few tools, but my favorite is IcoMoon. With this tool you can select from dozens of fonts and create your own font package, or even import your own SVG vectors.

All you need to do is select your icons, click generate font, and download!


Select your icons…
..and download the font!
..and download the font!
After you have your font, it’s time to add to your project. Add the font into {touch_app}/resources/fonts/, and add this path to your config.rb:

# Compass configurations
sass_path = dir
css_path = File.join(dir, "..", "css")
fonts_path = File.join(dir, "..", "fonts")
Hint: Because we’re defining the fonts_path I had an error like “Pictos fonts not found”. It’s also good to copy the pictos folder from touch/resources/themes/fonts to this new fonts/ directory.

For the last step you just need to include the font and use the icons on your app.scss, like this:

@include icon-font('SenchaConIcons', inline-font-files(
  'senchacon-icons/senchacon-icons.woff', woff,
  'senchacon-icons/senchacon-icons.ttf', truetype,
  'senchacon-icons/senchacon-icons.svg', svg
));

@include icon("menu"  , "\e009");
@include icon("search", "\e000");
@include icon("star"  , "\e001");
Updated June/5: In 2.2.1 you have to specify your font along with icon() mixin. Otherwise it will fallback to ‘Pictos’

@include icon("menu"  , "\e009", "SenchaConIcons");
@include icon("search", "\e000", "SenchaConIcons");
@include icon("star"  , "\e001", "SenchaConIcons");
Recap

Use a tool to pick icons and generate the font (IcoMoon, Fontello)
Add font into new directory {your_app}/resources/fonts
Copy Pictos font from Touch directory to the same {your_app}/resources/fonts to avoid errors
Add fonts_path into config.rb so Compass finds your font
Import the font icon in your app.scss
What about PNG?

PNG is bitmap based, while Fonts are vectorial based. The above mentioned tools provide hundreds of icons, so it’s pretty easy to find an existent font icon pre-built. If that’s not the case, you can convert PNG to SVG and then import into IcoMoon. There are tools for that, like VectorMagic, Online Image Converter or Inkscape. I haven’t try any of these but If you have, please let us know via comment.
- See more at: http://bruno.tavares.me/sencha-touch/adding-custom-font-icons-to-sencha-touch-2-2/#sthash.LOq6CDju.dpuf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值