我正在尝试使用导航栏(后退按钮, Headers 等)和标签栏(底部的工具栏)制作应用程序 . 我使用的子视图,所以我不担心状态栏,导航栏,标签栏的高度等,但我认为这是导致我麻烦,因为我似乎无法弄清楚如何设置导航和标签栏 .
这就是我所拥有的 . 我究竟做错了什么?
AppDelegate.h
(default for single view app)
AppDelegate.m
(default for single view app)
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) UIView *contentSubview;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)loadView{}
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor greenColor];
self.contentSubview = [[UIView alloc] init];
self.contentSubview.backgroundColor = [UIColor orangeColor];
[view addSubview:self.contentSubview];
self.view = view;
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.contentSubview.frame = CGRectMake(
0,
self.topLayoutGuide.length,
CGRectGetWidth(self.view.frame),
CGRectGetHeight(self.view.frame)-self.topLayoutGuide.length-self.bottomLayoutGuide.length
);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
3 回答
Swift3
Swift
xib方法:
来自here的教程
只有代码:
howto-implement-uinavigationcontroller-uitabbarcontroller-programmatically
故事板:
storyboards-tutorial-in-ios-7
Swift版本,在viewDidLoad中添加:
这在View Controller类中