You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.html
+24-3Lines changed: 24 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -440,11 +440,32 @@ <h4 class="exercise-start">
440
440
<p><strong>TIP</strong>: NativeScript also supports selecting elements by the <code>id</code> attribute. Refer to the docs for <ahref="/styling#supported-selectors">a full list of the supported selectors</a>.</p>
441
441
</blockquote>
442
442
<p>With these changes in place, you'll notice that the app looks halfway decent now, and also has a distinctly different look on iOS and Android:</p>
<p>Feel free to take some time to play with the look of this app before moving on. When you're ready, let's move on and add an image to this login screen.</p>
446
446
<h3id="images">Images</h3>
447
-
<p>TODO: Write this!</p>
447
+
<p>In NativeScript you use the <code><Image></code> UI element and its <code>src</code> attribute to add images to your pages. The <code>src</code> attribute lets you specify your image in three ways. The first (and simplest) way is to point at the URL of an image:</p>
<p>The second way is to point at an image that lives within your app's <code>app</code> folder. For example if you have an image at <code>app/images/logo.png</code>, you can use it with:</p>
<p>The third way, and the one Groceries uses, is to use platform-specific image resources. Let's add an image to the login screen and then discuss exactly what's happening.</p>
454
+
<h4class="exercise-start">
455
+
<b>Exercise</b>: Add a logo
456
+
</h4>
457
+
458
+
<p>In <code>login.xml</code>, add the <code><Image></code> below as the first child of the existing <code><StackLayout></code> tag:</p>
<p>The <code>res://</code> syntax tells NativeScript to use a platform-specific resource, in this case an image. Platform-specific resources go in your app's <code>app/App_Resources</code> folder. If you look there you'll find a few different image files, several of which are named <code>logo.png</code>.</p>
464
+
<p>Although more complex than putting an image directly in the <code>app</code> folder, using platform-specific images gives you more control over image display on different device dimensions. For example iOS lets you provide three different image files for devices with different pixel densities. As such you'll find logos named <code>logo.png</code>, <code>logo@2x.png</code>, and <code>logo@3x.png</code> in your <code>App_Resources/iOS</code> folder. For Android you'll find similar image files in <code>App_Resources/Android/drawable-hdpi</code> (for "high" dpi, or high dots-per-inch), <code>App_Resources/Android/drawable-mdpi</code> (for medium-dpi), and <code>App_Resources/Android/drawable-ldpi</code> (for low-dpi).</p>
465
+
<p>Once these files are in place the NativeScript framework knows how to pick the correct file; all you have to do is reference the image using <code>res://</code> and its base file name—i.e. <code>res://logo</code>. Here's what your login screen should look like on iOS and Android:</p>
<p>At this point your UI looks good, but the app still doesn't actually do anything. Let's look at how you can use JavaScript to add some functionality.</p>
Feel free to take some time to play with the look of this app before moving on. When you're ready, let's move on and add an image to this login screen.
307
307
308
308
### Images
309
309
310
-
TODO: Write this!
310
+
In NativeScript you use the `<Image>` UI element and its `src` attribute to add images to your pages. The `src` attribute lets you specify your image in three ways. The first (and simplest) way is to point at the URL of an image:
The second way is to point at an image that lives within your app's `app` folder. For example if you have an image at `app/images/logo.png`, you can use it with:
317
+
318
+
```XML
319
+
<Imagesrc="~/images/logo.png"></Image>
320
+
```
321
+
322
+
The third way, and the one Groceries uses, is to use platform-specific image resources. Let's add an image to the login screen and then discuss exactly what's happening.
323
+
324
+
<h4class="exercise-start">
325
+
<b>Exercise</b>: Add a logo
326
+
</h4>
327
+
328
+
In `login.xml`, add the `<Image>` below as the first child of the existing `<StackLayout>` tag:
The `res://` syntax tells NativeScript to use a platform-specific resource, in this case an image. Platform-specific resources go in your app's `app/App_Resources` folder. If you look there you'll find a few different image files, several of which are named `logo.png`.
337
+
338
+
Although more complex than putting an image directly in the `app` folder, using platform-specific images gives you more control over image display on different device dimensions. For example iOS lets you provide three different image files for devices with different pixel densities. As such you'll find logos named `logo.png`, `logo@2x.png`, and `logo@3x.png` in your `App_Resources/iOS` folder. For Android you'll find similar image files in `App_Resources/Android/drawable-hdpi` (for "high" dpi, or high dots-per-inch), `App_Resources/Android/drawable-mdpi` (for medium-dpi), and `App_Resources/Android/drawable-ldpi` (for low-dpi).
339
+
340
+
Once these files are in place the NativeScript framework knows how to pick the correct file; all you have to do is reference the image using `res://` and its base file name—i.e. `res://logo`. Here's what your login screen should look like on iOS and Android:
341
+
342
+

343
+

344
+
345
+
At this point your UI looks good, but the app still doesn't actually do anything. Let's look at how you can use JavaScript to add some functionality.
0 commit comments