iOS:UINavigationController的常用属性

来源:互联网 发布:php个人博客源码简单的 编辑:程序博客网 时间:2024/05/15 18:12
//从当前视图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];//导航栏的左右导航项,可以自定义buttonself.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];//隐藏navigationBarself.navigationController.navigationBarHidden = YES;

0 0