标签:
/* 初始化导航按钮 */ { credits = [ [ [ UIBarButtonItem alloc ] initWithTitle:@"Credits" style: UIBarButtonItemStylePlain target: appDelegate action:@selector(credits) ] autorelease ]; self.navigationItem.rightBarButtonItem = credits; segmentedControl = [ [ UISegmentedControl alloc ] initWithItems: nil ]; segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; [ segmentedControl insertSegmentWithTitle: @"Bunnies" atIndex: 0 animated: NO ]; [ segmentedControl insertSegmentWithTitle: @"Ponies" atIndex: 1 animated: NO ]; [ segmentedControl addTarget: self action: @selector(controlPressed:) forControlEvents:UIControlEventValueChanged ]; self.navigationItem.titleView = segmentedControl; segmentedControl.selectedSegmentIndex = 0; } return self; } - (void)controlPressed:(id) sender { [ self setPage ]; } - (void)setPage { int index = segmentedControl.selectedSegmentIndex; if (index == 0) { textView.text = @"OMG Bunnies!"; } else { textView.text = @"OMG Ponies"; } }
标签:
原文地址:http://www.cnblogs.com/JJFly/p/4297807.html