ios 将segment添加到nav上
/* 初始化导航按钮 */ { 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"; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。