diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index ccb3568af..74134f0b0 100644 --- a/apps/tests/ui/view/view-tests-common.ts +++ b/apps/tests/ui/view/view-tests-common.ts @@ -613,6 +613,20 @@ export var testIsVisible = function () { }); } +export var testSetInlineStyle = function () { + var lbl = new label.Label(); + + var expectedColor = "#ff0000"; + var expectedBackgroundColor = "#ff0000"; + + lbl.setInlineStyle(`color: ${expectedColor};background-color: ${expectedBackgroundColor};`); + + helper.buildUIAndRunTest(lbl, function (views: Array) { + TKUnit.assertEqual(lbl.color.hex, expectedColor); + TKUnit.assertEqual(lbl.backgroundColor.hex, expectedBackgroundColor); + }); +} + export var testBorderWidth = function () { helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { var lbl = views[0]; diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts index eb02cd8d0..0306dc9c9 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -923,6 +923,14 @@ export class View extends proxy.ProxyObject implements definition.View { return false; } + public setInlineStyle(style: string): void { + if (!types.isString(style)) { + throw new Error("Parameter should be valid CSS string!"); + } + + this._applyInlineStyle(style); + } + public _updateLayout() { // needed for iOS. } diff --git a/ui/core/view.d.ts b/ui/core/view.d.ts index b2fbfdc5d..b2eab2809 100644 --- a/ui/core/view.d.ts +++ b/ui/core/view.d.ts @@ -356,6 +356,12 @@ declare module "ui/core/view" { */ public focus(): boolean; + /** + * Sets in-line CSS string as style. + * @param style - In-line CSS string. + */ + public setInlineStyle(style: string) : void; + public getGestureObservers(type: gestures.GestureTypes): Array; /**