vanngoh
vanngoh

Reputation: 658

Nativescript - Set Inline Style Programmatic

https://docs.nativescript.org/api-reference/classes/_ui_core_view_.view#setinlinestyle

Is there any example of this function?

let image = new Image();
image.height = 300dp;
image.setInlineStyle('background-image: url(~/images/my_img.png)')

OR

image.setInlineStyle('{ background-image: url(~/images/my_img.png) }')

Both are not working.

Have I misunderstood the usage of setInlineStyle? Any idea? Thank you.

Upvotes: 2

Views: 319

Answers (2)

Shiva Prasad
Shiva Prasad

Reputation: 438

If all you want to do is set the backgroundImage, I'd recommend you to set it this way instead,

let image = new Image();
image.height = 300dp;
image.backgroundImage = "url('~/images/my_img.png')";

Upvotes: 1

Wilson Lau
Wilson Lau

Reputation: 253

Try this,

image.setInlineStyle('background-image: url("~/images/my_img.png")')

Upvotes: 2

Related Questions