导航控制器
UINavigation是导航控制器。
1:用于构建分层应用程序,管理多个视图的换入和换出的容器,自身提供视图切换动画效果。
2:他继承自UIViewController是所有视图控制器的基类
3:以栈的形式呈现
栈--先进后出
-入栈 puchViewController
-出栈 popViewController
-基栈
-栈顶
代码实现使用Storyboard的界面
在AppDelegate.m文件中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//==============1===============第一种方式从storyboard中取得界面
//1.创建Window并设置大小
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//2.从项目目录中获取故事版.
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main"bundle:[NSBundle mainBundle]];
//3.根据故事版ID来获取控制器
UIViewController *vC=[storyboard instantiateViewControllerWithIdentifier:@"vc"];
//=============2===============第二种方式不从storyboard中获取界面
// UIViewController *vC=[[UIViewController alloc]init];
//=============================
//4.创建导航栏控制器,并设置根视图控制器
UINavigationController *naVC=[[UINavigationController alloc]initWithRootViewController:vC];
//5.设置窗口的根视图控制
self.window.rootViewController=naVC;
//6.把窗口腿到屏幕的最前端
[self.window makeKeyAndVisible];
return YES;
}
UIBarButtonItem
常用属性:
leftBarButtonItem :左侧按钮
rightBarButtonItem :右侧按钮
backBarButtonItem:后退按钮
title :标题
titleView :标题视图
hidesBackButton :隐藏回退按钮
leftBarButtonItems :左侧按钮数组
rightBarButtonItems :右侧按钮数组
常用的方法;
-(instancetype)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action; :初始化按钮加标题
UINavigationBar
常用属性:
barStyle :导航栏风格
topItem :最上边的item
backItem:后退item
items :所有的item数组
tintColor :字体颜色
barTintColor :背景颜色
UIToolbar
常用属性:
barStyle :风格 ;
items :控件数组 ;
tintColor:控件颜色
barTintColor :背景颜色
模态视图
模态视图总是以全屏的形式实现.
具体使用
-弹出视图
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion;
-消失视图
-(void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion;
网友评论