Skip to content

Instantly share code, notes, and snippets.

@huytoan
Created January 30, 2012 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save huytoan/1704183 to your computer and use it in GitHub Desktop.
Save huytoan/1704183 to your computer and use it in GitHub Desktop.
flip a uibutton
- (void) viewDidLoad{
[super viewDidLoad];
isFrontViewShowing = YES;
UIButton *flipBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
flipBtn.frame = CGRectMake(100, 100, 100, 40);
[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