iPhone开发之在UINavigationBar上使用UISegmentedControl制作
2013-07-05 17:35 甘超波 阅读(628) 评论(0) 编辑 收藏 举报UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithFrame:CGRectMake(80.0f, 7.0f, 70.0f, 30.0f) ]; [segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"Nav-Page-Previous.png"] atIndex:0 animated:YES]; [segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"Nav-Page-Next.png"] atIndex:1 animated:YES]; segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; segmentedControl.momentary = YES; segmentedControl.multipleTouchEnabled=NO; [segmentedControl addTarget:self action:@selector(page:) forControlEvents:UIControlEventValueChanged]; UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl]; [segmentedControl release]; self.navigationItem.rightBarButtonItem = segButton; [segButton release]; - (IBAction)page:(id)sender { UISegmentedControl *seg = (UISegmentedControl *)sender; switch (seg.selectedSegmentIndex) { case 0: --_pageNum; break; case 1: ++_pageNum; break; default: break; } NSLog(@"%i", _pageNum); }
原文地址:http://www.wuleilei.com/blog/166
目前我正在专注NLP,请立刻加微信/QQ号 546611623, 免费送你原创《NLP高级执行师》高清视频