Personnaliser l'image correctement uiswitch?

j'ai UISwitch Dans ma candidature iOS 6, Qui comprend et éteint l'image.


self.testSwitch.onImage = [UIImage imageNamed:@"on"]; 
self.testSwitch.offImage = [UIImage imageNamed:@"off"];


À cette fin, j'utilise l'image de la largeur 77 Points et hauteurs 22 Points /154x44 dans la rétine/, Comme indiqué dans la documentation. Mais mon image ne correspond pas à mon uiswitch, Il semble moche, le style par défaut cache la mine, comme sur l'image ci-jointe.


Que dois-je installer pour le faire fonctionner correctement?
Invité:

Charles

Confirmation de:

Ici
http://www.apeth.com/iOSBook/ch25.html#_uiswitch
. Ce n'est pas exactement ce que vous voulez faire, mais cela montre la technique et vous aidera à commencer! Notez que j'utilise 79 sur 27 /Je ne sais pas où tu as eu vos chiffres/:


UIGraphicsBeginImageContextWithOptions/CGSizeMake/79,27/, NO, 0/;
[[UIColor blackColor] setFill];
UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake/0,0,79,27/];
[p fill];
NSMutableParagraphStyle* para = [NSMutableParagraphStyle new];
para.alignment = NSTextAlignmentCenter;
NSAttributedString* att =
[[NSAttributedString alloc] initWithString:@"YES" attributes:
@{
NSFontAttributeName:[UIFont fontWithName:@"GillSans-Bold" size:16],
NSForegroundColorAttributeName:[UIColor whiteColor],
NSParagraphStyleAttributeName:para
}];
[att drawInRect:CGRectMake/0,5,79,22/];
UIImage* im = UIGraphicsGetImageFromCurrentImageContext//;
UIGraphicsEndImageContext//;
self.sw2.onImage = im;


On dirait ça:

Gregoire

Confirmation de:

W. Apple ne pas Appearance API pour
UISwitch

. Vous pouvez définir la propriété. Tint color /
onTintColor

/./, Mais ce n'est pas ce que tu veux, je pense. Le problème avec le cadre UISwitch réside dans le fait qu'il y a une possibilité que Apple Rétribuez votre candidature.

Mais il y en a APIs Pour un commutateur personnalisé, tel que
RCSwitch

/
https://github.com/robertchin/rcswitch
/ ou
TTSwitch

. Bon manuel et exemple d'utilisation
RCSwitch

Vous pouvez trouver ici:
http://www.raywenderlich.com/2 ... witch
.

Pour répondre aux questions, connectez-vous ou registre