Créer un coin de bouton rectangle arrondi personnalisé en haut à gauche?
J'ai un bouton personnalisé que je veux faire en haut à gauche de la frontière de ressembler à la normale de rectangle arrondi.
J'ai trouvé un code qui permet tous les coins ronds:
_myButton.layer.cornerRadius = 8;
_myButton.layer.borderWidth = 0.5;
_myButton.layer.borderColor = [UIColor grayColor].CGColor;
_myButton.clipsToBounds = YES;
Comment puis-je corriger le code pour le rendre rond juste en haut à gauche?
Edit:
_myButton.layer.borderWidth = 2;
_myButton.layer.borderColor = [UIColor blackColor].CGColor;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_myButton.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(7.0, 7.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = _myButton.bounds;
maskLayer.path = maskPath.CGPath;
_myButton.layer.mask = maskLayer;
[maskLayer release];
Ce code ne fonctionne pas. Le bouton disparaît.
source d'informationauteur Ali
Vous devez vous connecter pour publier un commentaire.
Vous avez presque eu, mais, après la construction de votre
CAShapeLayer
l'utiliser pour ajouter de lui-même comme sous-couche de votre bouton de la couche, non pas comme un masque alpha pour masquer certaines parties de votre bouton (dans ce cas, les coins).