Titanium์์ Custom Font ์ฌ์ฉํ๊ธฐ (+FontAwesome)
Titanium์์ Custom Font๋ฅผ ์ฌ์ฉํ๋ ๋ฒ์ ์๋นํ ๊ฐ๋จํ๋ค. ํนํ FontAwesome ๊ฐ์ ์์ด์ฝ ํฐํธ ์ฌ์ฉํ๋ฉด ์ด๋ฏธ์ง ์์ ์์ด๋ ์ด์ ์์ด์ฝ์ ํธํ๊ณ ๋น ๋ฅด๊ฒ ์ฌ์ฉ๊ฐ๋ฅํ๋ค.
1. ํฐํธํ์ผ ์ค์น
font file์ Resource/fonts ํ์ผ์ ๋ณต์ฌํ๋ค. Alloy ํ๋ก์ ํธ์ ๊ฒฝ์ฐ app/asset/fonts/ ๋ app/lib/fonts์ ์ ์ฅํ๋ค. FontAwesome์ ๊ฒฝ์ฐ์๋ ๋ค์ด๋ฐ์์ ์์ถ ํ๋ฉด ๋์ค๋ ํฐํธ ํ์ผ์ค์ fontawesome-webfont.ttf ํ์ผ์ ์ด์ฉํ๋ฉด ๋๋ค. ์์น๊ฐ fonts๋ค font๊ฐ ์๋๋ค. (์ด ์ค์๋ก ์ฝ์ง์ ใ ใ )
2. tiapp.xml ์์ (iOS ์ธ๊ฒฝ์ฐ๋ง)
iOS ์ผ๊ฒฝ์ฐ tiapp.xml ํ์ผ์ ์๋ ์ฝ๋๋ฅผ ์์ ํ๋ฉด ๋๋ค. Titanium Doc Guide ๋์์๋ info.plist ํ์ผ์ ๋ณต์ฌํด์ ์์ ํ๋ ๋ฐฉ๋ฒ ๋ณด๋ค ํจ์ฌ ๊ฐ๋จํ๋ค. ์ฐธ๊ณ ๋ก ์ด๋ ๊ฒ ์ถ๊ฐํ๊ฒฝ์ฐ ํ๋ก์ ํธ๋ฅผ ํด๋ฆฐํ๊ณ ๋ค์ ๋น๋ํด๋ง ํ์ธ ํ ์ ์์๋ค.
<ios> <plist> <dict> <key>UIAppFonts</key> <array> <string>fonts/fontawesome-webfont.ttf</string> </array> </dict> </plist> </ios>
3. ๋. ์ด์ ๋ถํฐ ์ฌ์ฉ๊ฐ๋ฅํ๋ค.
๋ฐ๋ก ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค. ํ๊ฐ์ง ์ฃผ์ํ ์ ์ ์๋์ ๋์์๋ฏ์ด fontFamily์ ๋ค์ด๊ฐ๋ ๊ฐ์ด iOS์ Android์ ๊ฒฝ์ฐ ๋ค๋ฅด๋ค. iOS๋ friendly-name์ผ๋ก ํฐํธ ํ์ผ์ ์ด๋ฉด ์๋จ์ ๋์ค๋ ์ด๋ฆ์ด๊ณ , android์ ๊ฒฝ์ฐ๋ ํ์ฅ์๋ฅผ ์ ์ธํ ํ์ผ๋ช ์ด๋ค.
/* * Let's say you downloaded the "Spicy Rice" font from Google WebFonts. * You'd have a file named SpicyRice-Regular.ttf in your fonts directory */ var customFont = 'Spicy Rice'; // use the friendly-name on iOS if(Ti.Platform.osname=='android') { // on Android, use the "base name" of the file (name without extension) customFont = 'SpicyRice-Regular'; } var label1 = Titanium.UI.createLabel({ color:'#000', text:'I am Window 1', font:{ fontSize:40, fontFamily: customFont }, textAlign:'center', width:'auto' });
๋ํ FontAwesome ๊ฐ์ ๊ฒฝ์ฐ๋ "icon-glass": 0xf000์ ๊ฐ์ด ๊ฐ ์์ด์ฝ์ ํด๋นํ๋ string ๊ฐ์ ๋งค๋ฒ ์ฐพ์์ ๋ฃ๊ธฐ ๊ท์ฐฎ์๋ฐ k0sukey / TiIconicFont ๋ฅผ ์ด์ฉํ๋ฉด ์๋์ ๊ฐ์ด ๊ฐ๋จํ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
var fontawesome = require('lib/IconicFont').IconicFont({ font: 'lib/FontAwesome', ligature: false // optional }); var baloonLabel = Ti.UI.createLabel({ top: 20, right: 25, width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: '#000', font: { fontSize: 100, fontFamily: fontawesome.fontfamily() }, text: fontawesome.icon('icon-comment-alt') });











