L'état UIButton en surbrillance n'apparaît pas lorsque vous click un UIButton sélectionné

Je veux que mon UIButton affiche l'état en surbrillance lorsque je clique sur un button déjà sélectionné.

Fondamentalement, dans l'état en surbrillance, j'applique une image * .png comme UIButton backgroundImage pour donner un effet de compression.

Mais si le button est déjà dans l'état sélectionné Quand je clique dessus encore je ne peux pas voir l'état en surbrillance mais il va directement à l'état normal!

Regardez le numéro -> Vidéo du numéro!

Aidez-moi, s'il vous plaît

//0 init UIButton UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y, aSide, aSide)]; //1 Give it a backgroundColor [button setBackgroundColor:aColor]; [..] //2 Set titleLabel and its style [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted]; UIImage *shadowImage = [UIImage imageNamed:kBtnShadow]; shadowImage = [shadowImage stretchableImageWithLeftCapWidth:floorf(shadowImage.size.width/2) topCapHeight:floorf(shadowImage.size.height/2)]; [button setBackgroundImage:shadowImage forState: UIControlStateHighlighted]; [button setTitle:aLabel forState: UIControlStateNormal]; //3 Assign tag and Action [button setTag:tag]; [button addTarget:target action:a forControlEvents:UIControlEventTouchUpInside]; 

Les différents états: UIControlStateNormal , UIControlStateSelected et (UIControlStateSelected | UIControlStateHighlighted) sont tous réellement distincts. Si vous voulez que votre shadowImage s'applique à la fois dans l'état en surbrillance (uniquement) et dans l'état sélectionné + en surbrillance, vous devez également définir:

 [button setBackgroundImage:shadowImage forState:(UIControlStateHighlighted | UIControlStateSelected)] 

Dans swift ce serait:

 button.setBackgroundImage(shadowImage, forState: UIControlState.Selected.union(UIControlState.Highlighted)) 

Dans Swift v3 (nov. 2016):

 button.setBackgroundImage(shadowImage, for: UIControlState.selected.union(UIControlState.highlighted))