UIViewController 視圖控制器
抽象類:不能直接通過創(chuàng)建使用對象,需要定義該類的子類,然后再創(chuàng)建對象使用
創(chuàng)建VC對象
UIViewController*vc = [[UIViewControlleralloc]init];
創(chuàng)建對象
RootViewController*rootVC = [[RootViewControlleralloc]init];
設(shè)置根視圖(應(yīng)用創(chuàng)建好之后 window上放置的第一個頁面視圖)
self.window.rootViewController= rootVC;
內(nèi)存管理
[rootVCrelease];
視圖寫在viewDidLoad中
VC中 自帶一個view 用于鋪設(shè)視圖 默認顏色為透明
UIImageView圖片
相對路徑 ?修改后仍然可以正常顯示
絕對路徑 ?如果文件位置修改 就找不到了
收獲路徑(動態(tài)變化的絕對路徑)
參數(shù)1:文件名
參數(shù)2:文件后綴
NSString*path = [[NSBundlemainBundle]pathForResource:@"color"ofType:@"png"];
imgView.image= [UIImageimageWithContentsOfFile:path];
圓角
imgView.layer.cornerRadius= imgView.frame.size.width/2;
根據(jù)邊界把多余部分切掉
imgView.clipsToBounds=YES;
導(dǎo)航控制器
導(dǎo)航欄設(shè)置:controller(欄)/item(欄上的元素)
導(dǎo)航欄顯示/隱藏
(1)self.navigationController.navigationBarHidden=NO;
(2)self.navigationController.navigationBar.hidden=YES;
欄樣式
self.navigationController.navigationBar.barStyle=UIBarStyleBlack;
半透明效果
開始效果時屏幕左上角為坐標原點
關(guān)閉時導(dǎo)航欄的左下角為坐標原點
self.navigationController.navigationBar.translucent=YES;
欄背景顏色
self.navigationController.navigationBar.backgroundColor= [UIColoryellowColor];
欄顏色
self.navigationController.navigationBar.barTintColor= [UIColorgrayColor];
欄標題
(1)self.title=@"這是一個標題";
(2)self.navigationItem.title = @"這是一個猴賽雷的標題";
分段
UISegmentedControl*seg = [[[UISegmentedControlalloc]initWithItems:@[@"消息",@"電話"]]autorelease];
seg.frame=CGRectMake(0,0,100,30);
欄標題視圖
self.navigationItem.titleView= seg;
欄左側(cè)按鈕
self.navigationItem.leftBarButtonItem= [[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearchtarget:selfaction:@selector(left:)]autorelease];
欄右側(cè)按鈕
系統(tǒng)按鈕樣式
UIBarButtonItem*b1 = [[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemTrashtarget:selfaction:@selector(right1)]autorelease];
自定義按鈕圖片
UIBarButtonItem*b2 = [[[UIBarButtonItemalloc]initWithImage:[UIImageimageNamed:@"dianzan"]style:UIBarButtonItemStylePlaintarget:selfaction:@selector(right2)]autorelease];
self.navigationItem.rightBarButtonItems=@[b1, b2];
修改導(dǎo)航欄上內(nèi)容的顏色
self.navigationController.navigationBar.tintColor= [UIColorwhiteColor];
跳轉(zhuǎn)頁面
響應(yīng)事件
頁面間傳值
通過代理實現(xiàn)傳值
#warning協(xié)議1:聲明協(xié)議(定義一個帶參數(shù)的方法)
#warning協(xié)議2:定義代理人屬性
#warning協(xié)議3:返回上一頁之前讓代理人調(diào)用協(xié)議方法
#warning協(xié)議4.簽協(xié)議
#warning協(xié)議5:設(shè)置代理人
#warning協(xié)議6:實現(xiàn)協(xié)議方法
#warning屬性1:在第二頁聲明一個屬性用來保存數(shù)據(jù)
#warning屬性2:在push頁面之前傳值(創(chuàng)建對象之后push之前)
#warning屬性3:通過屬性給當前頁內(nèi)容賦值