// Create a segmented control.

长平狐 发布于 2012/08/13 15:20
阅读 121
收藏 0

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

// Create a segmented control.
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"up_button.png"] atIndex:0 animated:YES];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"down_button.png"] atIndex:1 animated:YES];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, 90, 30);
[segmentedControl setMomentary:YES];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
// Check if this is the first and / or the last page in order to enable or disable the back / forward button.
if ([recipesArray count] == 1) {
[segmentedControl setEnabled:NO forSegmentAtIndex:0];
[segmentedControl setEnabled:NO forSegmentAtIndex:1];
} else if ([currentIndex intValue] == 0) {
[segmentedControl setEnabled:NO forSegmentAtIndex:0];
} else if ([currentIndex intValue]+1 == [recipesArray count]) {
[segmentedControl setEnabled:NO forSegmentAtIndex:1];
}
// Initialize a bar button item with the segmented control as custom view and assign it to the right bar button item.
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.rightBarButtonItem = barButtonItem;
[segmentedControl release];

原文链接: http://www.cnblogs.com/chen1987lei/archive/2011/06/02/2067599.html
加载中
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部