关于视图控制器添加导航栏
我在网上找了一下,但是没有满意的回答,教学视频里面添加导航栏用的是storybook或者是在Application里面创建UINavigationController
其问题大概如下图所示:
8
收起
正在回答
2回答
你要是想在UIViewController上添加一个导航栏,那就自定义导航栏啊。
@interface ViewController ()
@property (nonatomic,strong) UIView *nBarView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.nBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
[self.nBarView setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:self.nBarView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"返回" forState:UIControlStateNormal];
button.backgroundColor = [UIColor redColor];
button.frame = CGRectMake(0, 0, 100, 44);
[button addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
[self.nBarView addSubview:button];
}
-(void)backAction:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}上面就是自定义当行栏的方法,点击方法你可以设置你想跳转的控制器。
iOS进阶:界面优化与数据存储
- 参与学习 516 人
- 提交作业 158 份
- 解答问题 637 个
本路径采用基础+案例方式,助你解开对界面优化、数据储存、屏幕适配的疑惑。6小时团购项目实战加最新版本Swift讲解,让你掌握更多iOS开发技巧。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星