diff --git a/apps/tests/ui/switch/switch-tests.ts b/apps/tests/ui/switch/switch-tests.ts index efeb8ba71..964a7faa9 100644 --- a/apps/tests/ui/switch/switch-tests.ts +++ b/apps/tests/ui/switch/switch-tests.ts @@ -3,6 +3,8 @@ import helper = require("../helper"); import viewModule = require("ui/core/view"); import bindable = require("ui/core/bindable"); import observable = require("data/observable"); +import color = require("color"); +import platform = require("platform"); //  // # Switch // Using a switch requires the Switch module. @@ -51,6 +53,31 @@ export function test_default_native_values() { helper.buildUIAndRunTest(mySwitch, testAction); } +// Uncomment this when find way to check android Drawable color set by setColorFilter() method. +if (platform.device.os === platform.platformNames.ios) { + exports.test_set_color = function () { + var mySwitch = new switchModule.Switch(); + mySwitch.color = new color.Color("red"); + + function testAction(views: Array) { + TKUnit.assert(mySwitch.color.ios.isEqual(mySwitch.ios.thumbTintColor), "mySwitch.color"); + }; + + helper.buildUIAndRunTest(mySwitch, testAction); + } + + exports.test_set_backgroundColor = function () { + var mySwitch = new switchModule.Switch(); + mySwitch.backgroundColor = new color.Color("red"); + + function testAction(views: Array) { + TKUnit.assert(CGColorEqualToColor(mySwitch.backgroundColor.ios.CGColor, mySwitch.ios.onTintColor.CGColor), "mySwitch.color"); + }; + + helper.buildUIAndRunTest(mySwitch, testAction); + } +} + export function test_set_TNS_checked_updates_native_checked() { var mySwitch = new switchModule.Switch(); function testAction(views: Array) { diff --git a/ui/styling/stylers.ios.ts b/ui/styling/stylers.ios.ts index 830983b4c..45f39dbe9 100644 --- a/ui/styling/stylers.ios.ts +++ b/ui/styling/stylers.ios.ts @@ -442,12 +442,12 @@ export class ProgressStyler implements definition.stylers.Styler { export class SwitchStyler implements definition.stylers.Styler { private static setColorProperty(view: view.View, newValue: any) { var sw = view.ios; - sw.thumbTintColor = UIColor.alloc().initWithCGColor((newValue).CGColor); + sw.thumbTintColor = newValue; } private static resetColorProperty(view: view.View, nativeValue: any) { var sw = view.ios; - sw.thumbTintColor = UIColor.alloc().initWithCGColor((nativeValue).CGColor); + sw.thumbTintColor = nativeValue; } private static getNativeColorValue(view: view.View): any { @@ -457,17 +457,17 @@ export class SwitchStyler implements definition.stylers.Styler { private static setBackgroundColorProperty(view: view.View, newValue: any) { var sw = view.ios; - sw.tintColor = UIColor.alloc().initWithCGColor((newValue).CGColor); + sw.onTintColor = view.backgroundColor.ios; } private static resetBackgroundColorProperty(view: view.View, nativeValue: any) { var sw = view.ios; - sw.tintColor = UIColor.alloc().initWithCGColor((nativeValue).CGColor); + sw.onTintColor = nativeValue; } private static getBackgroundColorProperty(view: view.View): any { var sw = view.ios; - return sw.tintColor; + return sw.onTintColor; } public static registerHandlers() {