2014-03-27 30 views
0

我有一個功能正常的UISwitch。我有兩張尺寸爲77 x 27像素的圖像,並將它們應用於ON和OFF圖像。UISwitch在iOS 7中顯示邊框

但是,其示出了如在下面的圖像中看到在IOS 7拉伸的邊界:

Image showing a stretched border圖像顯示拉伸的邊界,背景顏色是表示細,背景顏色白色

Image showing fine圖片被黑

我曾嘗試下面的代碼:

_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"]]; 
} 

我的問題是:如何使這個邊界正確的第一個圖像?

+2

'UISwitch'沒有預料到有它的視圖與'backgroundColor'操縱或它的層的'cornerRadius'。在iOS 7中,只有顏色('tintColor,'onTintColor'和'thumbTintColor')有望被修改。 –

回答

2
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];