开发者

UISegmentedControl Within UIToolBar

I know how to add a UISegmentedControl to a UIToolBar from within IB, but I am trying to do the same programmatically, because I am using a custom subclass of UISegmentedControl with doesn't have an XIB.

This is the code for the UISegmentedControl:

SVSegmentedControl *navSC = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@"List", @"Calendar", nil]];
navSC.delegate = self;
[self.view addSubview:navSC];
[navSC release];
navSC.开发者_StackOverflowcenter = CGPointMake(160, 70);

I was thinking of doing something like [self.toolbar addSubview:navSC], but that didn't show anything.


You need to use the UIToolbar method – setItems:animated: (detailed in the documentation):

UIBarButtonItem *segItem = [[UIBarButtonItem alloc] initWithCustomView:navSC];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
[toolBar setItems:[NSArray arrayWithObjects:spaceItem,segItem,spaceItem,nil] animated:YES];
[segItem release];
[spaceItem release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜