Note: You are on the beta version of our docs. This is a work in progress and may contain broken links and pages.
UI
Image
<Image>
is a UI component that shows an image from an ImageSource or from a URL.
🟢 Tip
When working with images following the best practices is a must.
Displaying an image from App_Resources
xml
<Image src="res://icon" stretch="aspectFill" />
Displaying an image relative to the app
directory
xml
<Image src="~/logo.png" stretch="aspectFill" />
Displaying an image from a URL
🟢 Note
Setting loadMode
to async
will prevent freezing the UI on Android when loading photos async (e.g. from online API)
xml
<Image
src="https://art.nativescript.org/logo/export/NativeScript_Logo_Blue_White.png"
stretch="aspectFill"
/>
Displaying a base64
-encoded image
xml
<Image src="data:Image/png;base64,iVBORw..." stretch="aspectFill" />
Rendering a font icon as image
xml
<Image src="font://" class="fas" />
Props
src
xml
<Image src="{{ src }}" />
<Image src="font://" />
<Image src="~/assets/images/cat.jpeg" />
ts
export class HelloWorldModel extends Observable {
src: string | ImageSource = '~/assets/images/cat.jpeg'
}
Gets or sets the source(ImageSource
) of the image.
imageSource
ts
ImageSource.fromUrl(url)
.then((imageSource: ImageSource) => {
image.imageSource = imageSource
})
.catch((error) => {
// handle errror
})
tintColor
xml
<Image src="{{ src }}" tintColor="#ff00ffaa"/>
Sets a color to tint template images.
stretch
xml
<Image src="{{ src }}" class="fas" stretch="aspectFill"/>
Gets or sets the way the image is resized to fill its allocated space. For valid values, see ImageStretch.
loadMode
xml
<Image src="{{ src }}" loadMode="sync"/>
Gets or sets the loading strategy for the images on the local file system. Valid values:
sync
- blocks the UI if necessary to display immediately. Only recommeded for small icons.async
(default
) - will load in the background, may appear with short delay, good for large images. When loading images from web they are always loaded async no regardlessloadMode
value.
...Inherited
For additional inherited properties, refer to the API Reference.
Native component
Android | iOS |
---|---|
android.widget.ImageView | UIImageView |