Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Forked from huytoan/Flip a Button
Last active October 4, 2015 03:18
Show Gist options
  • Save KentarouKanno/2569412 to your computer and use it in GitHub Desktop.
Save KentarouKanno/2569412 to your computer and use it in GitHub Desktop.
flip a uibutton
BOOL isFrontViewShowing;
- (void) viewDidLoad{
[super viewDidLoad];
isFrontViewShowing = YES;
UIButton *flipBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
flipBtn.frame = CGRectMake(100, 100, 100, 40);
flipBtn.backgroundColor = [UIColor redColor];
[flipBtn setTitle:@"Front" forState:UIControlStateNormal];
[flipBtn addTarget:self action:@selector(flipBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:flipBtn];
}
- (void) flipBtnTapped:(UIButton *)flipBtn{
isFrontViewShowing = !isFrontViewShowing;
[UIView animateWithDuration:0.3 animations:^{
if(isFrontViewShowing){
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:flipBtn cache:YES];
[flipBtn setTitle:@"Back" forState:UIControlStateNormal];
} else{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:flipBtn cache:YES];
[flipBtn setTitle:@"Front" forState:UIControlStateNormal];
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment