diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index ccb3568af..56421f56d 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 testSetStyle = function () { + var lbl = new label.Label(); + + var expectedColor = "#ff0000"; + var expectedBackgroundColor = "#ff0000"; + + lbl.setStyle(`color: ${expectedColor};background-color: ${expectedBackgroundColor};`); + + helper.buildUIAndRunTest(lbl, function (views: Array) { + TKUnit.assert(lbl.color.hex === expectedColor, "Actual: " + lbl.color.hex + "; Expected: " + expectedColor); + TKUnit.assert(lbl.backgroundColor.hex === expectedBackgroundColor, "Actual: " + lbl.backgroundColor.hex + "; Expected: " + 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..788fe65d0 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -923,6 +923,12 @@ export class View extends proxy.ProxyObject implements definition.View { return false; } + public setStyle(style: string): void { + if (types.isString(style)) { + this._applyInlineStyle(style); + } + } + public _updateLayout() { // needed for iOS. } diff --git a/ui/core/view.d.ts b/ui/core/view.d.ts index b2fbfdc5d..102d31440 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 setStyle(style: string) : void; + public getGestureObservers(type: gestures.GestureTypes): Array; /**