gpt4 book ai didi

iphone - UIToolBar 中的 UISegmentedControl

转载 作者:太空狗 更新时间:2023-10-30 03:35:52 25 4
gpt4 key购买 nike

我知道如何从 IB 中将 UISegmentedControl 添加到 UIToolBar,但我正在尝试以编程方式执行相同操作,因为我使用的是 UISegmentedControl 没有 XIB。

这是 UISegmentedControl 的代码:

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

我正在考虑做类似[self.toolbar addSubview:navSC] 的操作,但没有显示任何内容。

最佳答案

需要使用UIToolbar方法-setItems:animated:(详见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];

关于iphone - UIToolBar 中的 UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6460298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com