iOS:UINavigationController的常用属性

//从当前视图push到目标视图,如果视图已经存在,则不影响堆栈

[self.navigationController pushViewController:commentListVC animated:YES];

//返回上一控制器

[self.navigationController popViewControllerAnimated:YES];

//返回某一控制器

[self.navigationController popToViewController:[[UIViewController alloc] init] animated:YES];

//返回到根视图

[self.navigationController popToRootViewControllerAnimated:YES];

//B pop 返回A后,B是否释放要看之后的代码是否再次使用了B,如果后面的代码还使用到了B,则B所占的内存一直保留,有一种情况例外,在内存极度不足的情况下,IOS会遵从一定的策略有可能把B释放,B再次被使用的时候再重新创建

另外,即使pop后后面的代码不再使用B了,那么B的内存只是有可能被释放,释放的时机并不一定,这取决于垃圾回收器的回收策略

//去掉返回按钮的文字显示

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:NULL];

//自定义左右导航项一

UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];

UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];

UIBarButtonItem *bar1 = [[UIBarButtonItem alloc] initWithCustomView:btn1];

UIBarButtonItem *bar2 = [[UIBarButtonItem alloc] initWithCustomView:btn2];

//导航栏的左右导航项,可以自定义button

self.navigationItem.leftBarButtonItem = bar1;

self.navigationItem.rightBarButtonItem = bar1;

//也可以添加多个,后面跟数组,排列顺序是依次排列

self.navigationItem.leftBarButtonItems = @[bar1,bar2];

self.navigationItem.rightBarButtonItems = @[bar1,bar2];

//自定义左右导航项二

viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navItem_course"] style:UIBarButtonItemStylePlain target:self action:@selector(showCourse:)];

viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(logOut:)];

//设置导航栏的标题视图,可以自定义一个view,label都可以

self.navigationItem.titleView

// back 按钮背景为白色

[self.navigationBar setTintColor:[UIColor whiteColor]];

[self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_WITH_RGB(230, 230, 230), UITextAttributeTextColor,[UIFont boldSystemFontOfSize:18.0f],UITextAttributeFont, nil]];

//设置导航栏颜色

[self.navigationBar setBackgroundImage:[UIImage imageWithColor:COLOR_WITH_RGB(70, 70, 70) size:CGSizeMake(SCREEN_WIDTH, KNav_Height)] forBarMetrics:UIBarMetricsDefault];

//隐藏navigationBar

self.navigationController.navigationBarHidden = YES;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1. 有导航栏 2. 没有导航栏 3. 实例:创建一个导航项 4. 创建一个左边的按钮 5. 设置导航栏内容 ——...
    TenMios阅读 3,138评论 0 0
  • { 11、核心动画 需要签协议,但是系统帮签好 一、CABasicAnimation 1、创建基础动画对象 CAB...
    CYC666阅读 5,540评论 2 4
  • 1.不可变数组转变为可变数组声明实例变量的数组 必须记得实现 对于遍历数组找到对象后 如果还需要查找 记得先结束 ...
    小新xin阅读 4,461评论 0 1
  • 2016年24号听到聪聪同学告诉我乐视公司可以去霸面,然后我就怀着一个好奇的心思去试试。24号晚上就回了趟家,第二...
    codingQi阅读 2,924评论 0 1
  • 今晚看了潇洒姐书中关于梦想的解答 潇洒姐说梦想就是找个榜样 你想成为一个怎样的人 我想成为一个怎样的人呢? 我应该...
    咖啡梁拌阅读 1,099评论 0 0

友情链接更多精彩内容