Created
June 22, 2012 08:24
-
-
Save ttsubono/2971304 to your computer and use it in GitHub Desktop.
NavigationBarに置いたUISegmentedControlのインスタンスを水平回転
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)addNavigationBarButton { | |
// 黒色のNavigationBarに黒色のボタンの場合 | |
// setmentedControlObjectがメンバー変数としてあること | |
NSArray *controlItems = [NSArray arrayWithObjects:@"BBB", nil]; | |
segmentedControlObject = [[UISegmentedControl alloc] initWithItems:controlItems]; | |
segmentedControlObject.momentary = YES; | |
segmentedControlObject.segmentedControlStyle = UISegmentedControlStyleBar; | |
segmentedControlObject.tintColor = [UIColor darkGrayColor]; | |
[segmentedControlObject addTarget:self action:@selector(flipNavigationBarButton) forControlEvents:UIControlEventValueChanged]; | |
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:segmentedControlObject]; | |
self.navigationItem.rightBarButtonItem = button; | |
[button release]; | |
} | |
} | |
- (void)flipNavigationBarButton { | |
#define FLIP_ANIMATION_DURATION 0.5 | |
static BOOL flipFromLeft = YES; | |
[UIView animateWithDuration:FLIP_ANIMATION_DURATION | |
animations:^ { | |
if (flipFromLeft) { | |
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft | |
forView:segmentedControlObject | |
cache:YES]; | |
[segmentedControlObject setTitle:@"AAA" | |
forSegmentAtIndex:0]; | |
} else { | |
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight | |
forView:segmentedControlObject | |
cache:YES]; | |
[segmentedControlObject setTitle:@"BBB" | |
forSegmentAtIndex:0]; | |
} | |
} | |
]; | |
flipFromLeft = !flipFromLeft; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UISegmentedControl Class Reference
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISegmentedControl_Class/Reference/UISegmentedControl.html