Question

I have a UISwitch whose functionality is working fine. I have 2 images of size 77 x 27 pixels and applying them for ON and OFF images.

But, its showing a stretched border in IOS 7 as seen in the images below:

Image showing a stretched border Image showing a stretched border, Background colour is white

Image showing fine Image showing fine, Background colour is black

I have tried the following code :

_switcherTheme = [[UISwitch alloc] initWithFrame:switchRect];
_switcherTheme.backgroundColor = [UIColor colorWithRed:36.0/255.0 green:41.0/255.0 blue:45.0/255.0 alpha:1.0];
_switcherTheme.layer.cornerRadius = 16.0;
[_switcherTheme setOnTintColor:[UIColor colorWithRed:223.0/255.0 green:245.0/255.0 blue:241.0/255.0 alpha:1.0]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) {
    [_switcherTheme setOnImage:[UIImage imageNamed:@"color_light.png"]];
    [_switcherTheme setOffImage:[UIImage imageNamed:@"color.png"]];
}

My question is : How to make this border correct for 1st image ?

OTHER TIPS

UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
mySwitch.backgroundColor = [UIColor greenColor];
mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
[self addSubview:mySwitch];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top