如何为所有文本声明应用程序范围的自定义字体
How to declare app-wide custom font for all text
我已经将自定义字体放入我的 app/resources/<platform>/fonts
文件夹中,并在我的应用程序中的多个 UI 元素上使用了它,但是有没有办法将其声明为跨文本的默认字体整个应用程序?
我假设这可能会在 tiapp.xml
中完成?否则,我能想到的实现此目的的唯一方法是在 app.tss
中为每个元素单独设置字体,但这很快就会变得乏味,并且可以跳过一个元素。我相信一定有更好的解决方案。
实际上,您确实需要在 app.tss 中对您想要设置样式的所有对象类型进行定义。唯一的办法,我想。
TSS 文件是在应用范围内应用自定义字体的最佳位置 text/labels/buttons 等
你可以这样做:
app.tss
"Label" : {
font : {
fontFamily : 'custom_font_1' // app->assets->fonts folder
}
}
".custom_font" : {
font : {
fontFamily : 'custom_font_file' // app->assets->fonts folder
}
}
ViewName.xml
<Label class="custom_font" text="Hello there!" color="black" />
<Label class="view-class" text="Hello there!" color="blue" />
<Label text="Hello there!" color="red" />
ViewName.tss
".view-class" : {
font : {
fontFamily : 'another_font' // app->assets->fonts folder
}
}
在这个例子中,我们在3处定义了不同的字体。 2 字体在 app.tss 文件中,1 字体在 ViewName.tss 文件.
在ViewName.xml文件中:
- 第一个标签将使用 custom_font class 来自 app.tss
- 第二个标签将使用 view-class class 来自它自己的 ViewName.tss
- 第三个标签将使用 默认标签字体 来自 app.tss
所以,我向您介绍了不同的方法来满足每个应用程序的要求。您的特殊情况是第 3 个标签。
就像您在 app.tss 中使用了 Label 一样,您可以使用任何 Titanium 文本类型元素,例如 TextField,文本区域、按钮等
在此处参考更多内容:Global Styling & Themes in Titanium
我已经将自定义字体放入我的 app/resources/<platform>/fonts
文件夹中,并在我的应用程序中的多个 UI 元素上使用了它,但是有没有办法将其声明为跨文本的默认字体整个应用程序?
我假设这可能会在 tiapp.xml
中完成?否则,我能想到的实现此目的的唯一方法是在 app.tss
中为每个元素单独设置字体,但这很快就会变得乏味,并且可以跳过一个元素。我相信一定有更好的解决方案。
实际上,您确实需要在 app.tss 中对您想要设置样式的所有对象类型进行定义。唯一的办法,我想。
TSS 文件是在应用范围内应用自定义字体的最佳位置 text/labels/buttons 等
你可以这样做:
app.tss
"Label" : {
font : {
fontFamily : 'custom_font_1' // app->assets->fonts folder
}
}
".custom_font" : {
font : {
fontFamily : 'custom_font_file' // app->assets->fonts folder
}
}
ViewName.xml
<Label class="custom_font" text="Hello there!" color="black" />
<Label class="view-class" text="Hello there!" color="blue" />
<Label text="Hello there!" color="red" />
ViewName.tss
".view-class" : {
font : {
fontFamily : 'another_font' // app->assets->fonts folder
}
}
在这个例子中,我们在3处定义了不同的字体。 2 字体在 app.tss 文件中,1 字体在 ViewName.tss 文件.
在ViewName.xml文件中:
- 第一个标签将使用 custom_font class 来自 app.tss
- 第二个标签将使用 view-class class 来自它自己的 ViewName.tss
- 第三个标签将使用 默认标签字体 来自 app.tss
所以,我向您介绍了不同的方法来满足每个应用程序的要求。您的特殊情况是第 3 个标签。
就像您在 app.tss 中使用了 Label 一样,您可以使用任何 Titanium 文本类型元素,例如 TextField,文本区域、按钮等
在此处参考更多内容:Global Styling & Themes in Titanium