Skip to content

add section about icon fonts in Image #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/ns-ui-category/icon-fonts/basics/article.md

This file was deleted.

6 changes: 3 additions & 3 deletions app/ns-ui-category/icon-fonts/icon-fonts-page.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const ListViewLinksModel = require("../../links-view-model");
const link = require("../../link");
const navigationLinks = [
new link("Basics", "ns-ui-category/icon-fonts/basics/basics-page"),
new link("Code Behind", "ns-ui-category/icon-fonts/code-behind/code-behind-page")
new link("Usage", "ns-ui-category/icon-fonts/usage/usage-page"),
new link("Tips & Tricks", "ns-ui-category/icon-fonts/tips-and-tricks/tips-and-tricks-page")
];
const navigationLinksTsc = [
new link("Code Behind", "ns-ui-category/icon-fonts/code-behind/code-behind-ts-page")
new link("Tips & Tricks", "ns-ui-category/icon-fonts/tips-and-tricks/tips-and-tricks-ts-page")
];
function onNavigatingTo(args) {
const page = args.object;
Expand Down
1 change: 1 addition & 0 deletions app/ns-ui-category/icon-fonts/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ position: 265
slug: icon-fonts
previous_url: /icon-fonts
---
example-order: usage, tips-and-tricks

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions app/ns-ui-category/icon-fonts/usage/article.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

The example demonstrates, how to use setup the `font-family` property via CSS and how to define the needed icons via XML.

<snippet id='icon-font-xml-def'/>
<snippet id='icon-font-css-class-def'/>

WIth NativeScript 6 and above, we can use icon fonts with `Image` elements. For that purpose the `font://` prefix is needed to set the icon font code.

<snippet id='icon-font-xml-images'/>
<snippet id='icon-font-css-class-def'/>

>> **Note:** Images have specific stretch options (`none`, `aspectFit`, `aspectFill`). At the same time the icon fonts are having `font-size` which can contorl the size of our font. If you want to set the size of your icon through the `font-size` property then set `stretch` property to `none`. Any other values of the stretch property (including the default one) will cause the icon to be resized by measuring the image (or if there is no sizes set, the parent layout in whcih the image is nested).
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
<!-- << icon-font-xml-def -->

<!-- Using font icons in Images requires the font:// prefix -->
<Image src="font://&#xf019;" class="far"></Image>
<Image src="font://&#xf015;" stretch="none" class="fas"></Image>

<!-- >> icon-font-xml-images -->
<!--
In case, when the stretch property is set to aspectFit or aspectFill
the font-sizde will be disreagarderd and the image will take the vailable space
assigned through width/height or through its parent size

Setting the stretch property to none will allow using the font-size property
-->
<Image src="font://&#xf51e;" stretch="none" class="fas"></Image>
<!-- << icon-font-xml-images -->
</StackLayout>
</Page>
1 change: 1 addition & 0 deletions app/ns-ui-widgets-category/tabs/tabs-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ListViewLinksModel = require("../../links-view-model");
const link = require("../../link");

const navigationLinks = [
new link("Usage", "ns-ui-widgets-category/tabs/usage/usage-page"),
new link("Theming", "ns-ui-widgets-category/tabs/theming/theming-page"),
Expand Down