
####iOS7 Programming Cookbook 第一章学习笔记 UIBarButtonItem
#####Adding Buttons to Navigation Bars Using UIBarButtonItem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
- (void) segmentedControlTapped:(UISegmentedControl *)paramSender{ switch (paramSender.selectedSegmentIndex){ case 0:{ NSLog(@"Up"); break; } case 1:{ NSLog(@"Down"); break; } } } - (void)viewDidLoad{ [super viewDidLoad]; self.title = @"First Controller"; NSArray *items = @[ @"Up", @"Down" ]; UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:items]; segmentedControl.momentary = YES; [segmentedControl addTarget:self action:@selector(segmentedControlTapped:) forControlEvents:UIControlEventValueChanged]; UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; [self.navigationItem setRightBarButtonItem:rightBarButton animated:YES]; }
|

##iOS7 Programming Cookbook 第一章学习笔记 UIButton
###Adding Buttons to the User Interface with UIButton
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
- (void) buttonIsPressed:(UIButton *)paramSender{ NSLog(@"Button is pressed."); } - (void) buttonIsTapped:(UIButton *)paramSender{ NSLog(@"Button is tapped."); } - (void)viewDidLoad{ [super viewDidLoad]; UIImage *normalImage = [UIImage imageNamed:@"NormalBlueButton"]; UIImage *highlightedImage = [UIImage imageNamed:@"HighlightedBlueButton"]; self.myButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.myButton.frame = CGRectMake(110.0f, 200.0f, 100.0f, 44.0f); [self.myButton setBackgroundImage:normalImage forState:UIControlStateNormal]; [self.myButton setTitle:@"Normal" forState:UIControlStateNormal]; [self.myButton setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; [self.myButton setTitle:@"Pressed" forState:UIControlStateHighlighted]; [self.myButton addTarget:self action:@selector(buttonIsPressed:) forControlEvents:UIControlEventTouchDown]; [self.myButton addTarget:self action:@selector(buttonIsTapped:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.myButton]; }
|

Reference
近期评论