我想在顶部有标签栏。
所以我在 XCode 中创建了一个新项目。添加了一个视图,然后在该视图中我添加了(滚动条、文本和另一个视图)。见图片。
我想要的是让我的标签栏在顶部。然后在中间是标签栏的内容,下面是一个小的版权文本。见图片。
不知道如何正确地做到这一点。我试图动态创建 UITabBarController,然后将其分配到顶部的视图中。(图片上的顶部空白区域专用于标签栏)。
这是我初始化 MainWindow 的代码。
主窗口.h
#import <UIKit/UIKit.h>
@class Intro;
@interface MainWindow : UIViewController
@property (strong, nonatomic) IBOutlet UIScrollView *mainContentFrame;
@property (strong, nonatomic) IBOutlet UIView *mainTabBarView;
@property (strong, nonatomic) UITabBarController *mainTabBar;
@property (nonatomic, strong) Intro *intro; // Trying to get this tab to show in the tab bar
@end
主窗口.m
#import "MainWindow.h"
#import "Intro.h"
@interface MainWindow ()
@end
@implementation MainWindow
@synthesize mainContentFrame = _mainContentFrame;
@synthesize mainTabBarView = _mainTabBarView;
@synthesize mainTabBar = _mainTabBar;
@synthesize intro = _intro;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
_intro = [[Intro alloc] init];
NSArray *allViews = [[NSArray alloc] initWithObjects:_intro, nil];
[super viewDidLoad];
// Do any additional setup after loading the view.
_mainTabBar = [[UITabBarController alloc] init];
[_mainTabBar setViewControllers:allViews];
[_mainTabBarView.window addSubview:_mainTabBar.tabBarController.view];
}
- (void)viewDidUnload
{
[self setMainTabBar:nil];
[self setMainContentFrame:nil];
[self setMainContentFrame:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
我缺少什么让这个工作?希望内容最终出现在滚动视图中,以便所有选项卡都可以滚动。