| 测试测试过的 | ✗ |
| 语言语言 | Obj-CObjective C |
| 许可 | MIT |
| 发布上次发布 | 2014年12月 |
由Scott Berrevoets维护。
SBSegmentedViewController 是一个自定义视图控制器容器,它使用分段控件在视图控制器之间切换。它可以用于 iOS 5.0+,尽管示例项目的部署目标设置为 iOS 6.0。
SBSegmentedViewController 非常容易使用,可以使用故事板或以编程方式设置。它设置了一个容器视图控制器,使用 UISegmentedControl 在其子视图控制器之间切换。分段控件可以放在包含 SBSegmentedViewController 的导航控制器中的导航栏或工具栏中。此位置可以通过 position 属性设置(选项为 SBSegmentedViewControllerPositionNavigationBar 或 SBSegmentedViewControllerPositionToolbar)。
按照以下步骤从故事板中实例化 SBSegmentedViewController
SBSegmentedViewControllerSBSegmentedViewController 嵌入导航控制器中SBSegmentedViewController 部分的其他视图控制器title 属性。这是一个要求,因为标题属性用于设置段的标题。SBSegmentedViewController 场景控制拖到步骤 2 中创建的视图控制器上-[SBSegmentedViewController addStoryboardSegments:] 并传入一个匹配切换标识符的 NSArray 对象的 NSString 字符串数组下面的代码是当 SBSegmentedViewController 以编程方式创建时在 application:didFinishLaunchingWithOptions: 中使用的一个示例
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MyViewController *myVC1 = [[MyViewController alloc] initWithNibName:@"MyVC1" bundle:nil];
MyOtherViewController *myVC2 = [[MyViewController alloc] initWithNibName:@"MyVC2" bundle:nil];
SBSegmentedViewController *segmentedController = [[SBSegmentedViewController alloc] initWithViewControllers:@[myVC1, myVC2]];
// Or, we could choose our own titles:
// SBSegmentedViewController *segmentedController = [[SBSegmentedViewController alloc] initWithViewControllers:@[myVC1, myVC2] titles:@[@"Segment 1", @"Segment 2"]];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:segmentedController];
[self.window makeKeyAndVisible];
}当然,您不必将 SBSegmentedViewController 作为根视图控制器使用,您可以直接将其推送到导航控制器、以模态方式显示它,或者做任何正常视图控制器可以做的事情。
这个仓库中分发的代码适用于 MIT 许可。