注:本文並不是絕對原創 大部份內容摘自 http://blog.csdn.net/hengshujiyi/article/details/20943045php
文中有些方法可能已過期並不適用於如今的開發環境。
html
其實在代碼裏仍是能夠設置的,那就是刪除背景view
[[self.searchBar.subviews objectAtIndex:0] removeFromSuperview]; ios
1 字母 日期或時間元素 表示 示例 2 G Era 標誌符 Text AD 3 y 年 Year 1996 96 4 M 年中的月份 Month July; Jul; 07 5 w 年中的週數 Number 27 6 W 月份中的週數 Number 2 7 D 年中的天數 Number 189 8 d 月份中的天數 Number 10 9 F 月份中的星期 Number 2 10 E 星期中的天數 Text Tuesday; Tue 11 a Am/pm 標記 Text PM 12 H 一天中的小時數(0-23) Number 0 13 k 一天中的小時數(1-24) Number 24 14 K am/pm 中的小時數(0-11) Number 0 15 h am/pm 中的小時數(1-12) Number 12 16 m 小時中的分鐘數 Number 30 17 s 分鐘中的秒數 Number 55 18 S 毫秒數 Number 978 19 z 時區 General time zone Pacific Standard Time; PST; GMT-08:00 20 Z 時區 RFC 822 time zone -0800
[注意]在開發中,若是使用年月日,用NSDateFormatter setFormat :@"yyyy-MM-dd",若是是使用小時和分鐘,設置爲:"HH:mm",切記不要設置「HH-mm」,這樣會出錯的。
舉例:c++
1 //建立一個時間對象 2 NSData * date = [NSDate date]; 3 //打印時間 4 NSLog(@"today is %@",date); 5 6 //再獲取的時間date減去24小時的時間(昨天的這個時候) 7 NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-(24*60*60)]; 8 NSLog(@"yesterday is %@",yesterday);//打印昨天的時間 9 10 /*字符串換成時間*/ 11 //設置一個字符串的時間 12 NSString *datestring = [NSString stringWithFormat:@"1999-09-03"]; 13 //想要設置本身想要的格式,能夠用nsdateformatter這個類,這裏是初始化 14 NSDateFormatter * dm = [[NSDateFormatter alloc]init]; 15 //指定輸出的格式 這裏格式必須是和上面定義字符串的格式相同,不然輸出空 16 [dm setDateFormat:@"yyyy-MM-dd"]; 17 //把字符串的時間轉換成Date對象,用dateFromString方法 18 NSDate * newdate = [dm dateFromString:datestring]; 19 //輸出 20 NSLog(@"newdate is %@",newdate); 21 22 23 /*把時間轉換成字符串*/ 24 //把Date對象轉換成String對象 用stringFromDate方法 25 NSString * datestring2 = [dm stringFromDate:newdate]; 26 //打印 27 NSLog(@"datestring2 is %@",datestring2);
[self PerformSegueWithIdentifier:@"targetViewController",self]; 就能夠了,但是我想實例化想要跳轉的控制器,而後設置某一屬性的值,這樣跳轉後控制器獲取那個屬性,就會獲得值了,但是這樣作會有一個問題:
主 界面控制器若是使用了navigatorViewController,而且是其RootViewController,等到在主界面設置功能,點擊某一 功能,想push到一個新頁面時,問題就來了,你會發現毫無反應,沒有報錯,只是segue沒法跳轉。後來終於找到緣由:就是我在登錄控制器跳轉時沒有使 用segue的方法,而是用代碼self.storyboard,加載一個新類,具體原理目前尚未搞明白,先把出問題的代碼記錄下來,回頭補之:
代碼這樣作,會致使其後沒法使用navigatorViewController作push跳轉 正則表達式
簡單點說,就是當字典,數組爲null時,後臺打印的輸出結果是這樣:
而後,咱們須要在代碼判斷時利用[NSNull null]來判斷,具體如:
isEqual:[NSNull null] 就搞定了,nsarray也是一樣的道理。
控制檯打印:str=(null) 表明着 字符串或數組或字典是一個空指針,(而非空字符串)判斷的時候,直接用:
if(str == nil)就能夠了。以下圖所示:
而控制檯打印:str = <null>,表明着這是一個空字符串,賦值爲空,指針是存在的,只是內容爲空,這種判斷須要使用:
if(str is equal [NSNull null ]) ,由於在ios上,內容爲空不能簡單的判斷str==null(null 在ios上得用[NSNull null])
通常這種狀況是,服務器那邊是null,直接返回@"null"的字符串,這樣在ios這邊很差判斷,最好跟後臺溝通,若是遇到null值,返回@"",好作判斷 json
只需在加載時,添加這樣的話就能夠了: windows
testView.layer.cornerRadius = 6;
testView.layer.masksToBounds = YES;
注意,須要 import <QuartzCore/QuartzCore.h> 導入,不然,不能識別cornerRadius和masksToBounds。
uiview設置背景圖片:api
[theMainView setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"bg.png"]]];
imageName 緩存,下面方法不緩存數組
1 NSString *thePath = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"jpeg"]; 2 UIImage *prodImg = [[UIImage alloc] initWithContentsOfFile:thePath"]; 3 controller.productImg.image = prodImg; 4 [prodImg release];
1-1Did End On Exit 調用下面事件當點擊鍵盤return得時候就會隱藏鍵盤瀏覽器
1 - (IBAction)textFieldShouldReturn:(UITextField *)textField { 2 //[sender resignFirstResponder]; 3 if (textField == chi) { 4 [chi resignFirstResponder]; 5 double m=[chi.textdoubleValue]/3.003; 6 double f=m *3.2808; 7 meter.text=[[NSStringalloc] initWithFormat:@"%.4f",m]; 8 feet.text=[[NSStringalloc] initWithFormat:@"%.4f",f]; 9 } 10 if (textField == meter) { 11 [meter resignFirstResponder]; 13 } 14 if (textField == feet) { 15 [feet resignFirstResponder]; 16 } 17 }
1-2 點擊屏幕得時候隱藏鍵盤
1 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 2 UITouch *touch=[[event allTouches] anyObject]; 3 if (touch.tapCount >=1) { 4 [chi resignFirstResponder]; 5 [meter resignFirstResponder]; 6 [feet resignFirstResponder]; 7 } 8 }
1-2 的方法至關於屏幕任何位置的點擊事件(除了各組件的點擊處)能夠在這個方法裏執行要隱藏或remove的view。
1-3 隱藏鍵盤 方法二
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; }
只須要在TextField屬性中的Secure(安全的)勾選上或者設置 passWordTextField.secureTextEntry=YES; 就能夠了。顯示apple默認的密文顯示方式。
1 NSString *regex =[NSString stringWithFormat:@"^1(3[4-9]|5[012789]|8[2378]|47)\\d{8}$"]; 2 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; 3 BOOL isMatch = [predicate evaluateWithObject:editPhoneField.text];
1, 在項目的Supporting Files下尋找infoPlist.strings文件,打開後會看到一片空白(英文默認是跟隨項目名稱顯示)。此時,能夠就地添加一句代 碼:CFBundleDisplayName="愛貝通";這樣的話,不管手機設置英文語言仍是中文語言,應用程序都會顯示設置的名稱。
2,爲了國際化而言,咱們最好建立一個chinese專有的infoPlist.strings文件。
如上圖所示,添加一箇中文的plist
而後打開添加代碼:
這個時候,大功告成。部署在模擬器或真機中吧,你的手機設置(中/英)文語言,它就會調用相應的配置文件。
1 // testAppDelegate.m 2 // test 3 // 4 // Created by gaohf on 11-5-24. 5 // Copyright 2011 __MyCompanyName__. All rights reserved.
在終端中執行如下命令:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "COMPANY";}'
執行後效果
1 // testAppDelegate.m 2 // test 3 // 4 // Created by gaohf on 11-5-24. 5 // Copyright 2011 COMPANY. All rights reserved.
只須要在要添加view時侯這樣寫:
[[UIApplication sharedApplication].keyWindow addSubview:waitingview];
這樣,直接把waitingview添加到了uiWindow上,而不是self.view上。再次運行,會發現屏幕所有區域都已經遮擋住了。
StoryboardApp[8593:207] Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?
StoryBoard中沒有一個view controller設置了Initial Scene。您須要選擇一個view conroller做爲story board的第一個界面:
在項目中添加以下代碼:
//設置背景顏色:
1 UIColor *itemcolor = [UIColor colorWithRed:100.0f/255.0f green:176.0f/255.0f blue:0.0f/255.0f alpha:0.3f]; 2 self.navigationController.navigationBar.tintColor = itemcolor;
//設置自定義的圖片:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg.png"] forBarMetrics:UIBarMetricsDefault];
5.0以上,api有了上面setBackgroundImage的方法,能夠直接設置,若是項目須要適配5.0如下版本的設備,最好加一個判讀,是否有此函數,
有則設置,沒有就經過drawRect方法設置。 另外:設置背景圖片沒法匹配backButton或rightButtonItem,因此返回按鈕或右邊自定義的
Bar button Item須要自行處理。
在storyboard或xib中,添加一個uiview,屬性設置欄通常都有設置背景顏色,樣式,透明度alpha,可是沒有提供設置image,只有在imageview中才有,
因此,要想設置背景圖片,只能在代碼中設置,以下:
[leftNaviView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"pabb_leftnaviview_bg.png"]]];
這樣,背景就能夠變成想要的圖片了。另外,設置大小:
[leftNaviView setFrame:CGRectMake(9, 60, 120, 250)];
效果圖:
1 //如下是經過id打開此軟件的評價 2 //int m_appleID = 576337094; 3 //NSString *str = [NSString stringWithFormat: 4 //@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d", 5 //m_appleID ]; 6 7 //如下是經過appstore連接到本身應用在商店的位置 8 NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/cn/app/huo-xing-she-xin-dian/id549425594?l=en&mt=8"]; 9 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
把以上代碼直接拷貝到想要實現點擊跳轉的操做方法內就能夠了,經過appID,隨意能夠經過appstore打開應用,直接用url就能夠連接到了。
很簡單,通常都用在檢查更新的時候。
只須要在相應的代碼中寫入:
一、調用 電話phone
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://4008008288"]];
二、調用自帶 瀏覽器 safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.abt.com"]];
三、調用 自帶mail
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@abt.com"]];
四、調用 SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
5,跳轉到系統設置相關界面
1 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
其中,發短信,發Email的功能只能填寫要發送的地址或號碼,沒法初始化發送內容,若是想實現內容的話,還須要更復雜一些,
實現其各自的委託方法。
若須要傳遞內容能夠作以下操做:
1 //加入:MessageUI.framework 2 #import <MessageUI/MFMessageComposeViewController.h> 3 4 //實現代理:MFMessageComposeViewControllerDelegate 5 6 //調用sendSMS函數 7 //內容,收件人列表 8 - (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients 9 { 11 MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease]; 13 if([MFMessageComposeViewController canSendText]) 15 { 17 controller.body = bodyOfMessage; 19 controller.recipients = recipients; 21 controller.messageComposeDelegate = self; 23 [self presentModalViewController:controller animated:YES]; 25 } 27 } 28 29 // 處理髮送完的響應結果 30 - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result 31 { 32 [self dismissModalViewControllerAnimated:YES]; 34 if (result == MessageComposeResultCancelled) 35 NSLog(@"Message cancelled") 36 else if (result == MessageComposeResultSent) 37 NSLog(@"Message sent") 38 else 39 NSLog(@"Message failed") 40 }
發送郵件的爲:
1 //導入MFMailComposeViewController 2 #import <MessageUI/MFMailComposeViewController.h> 3 //實現代理:MFMailComposeViewControllerDelegate 4 5 //發送郵件 6 -(void)sendMail:(NSString *)subject content:(NSString *)content{ 7 MFMailComposeViewController *controller = [[[MFMailComposeViewController alloc] init] autorelease]; 9 if([MFMailComposeViewController canSendMail]) 11 { 13 [controller setSubject:subject]; 15 [controller setMessageBody:content isHTML:NO]; 17 controller.mailComposeDelegate = self; 19 [self presentModalViewController:controller animated:YES]; 21 } 22 } 23 24 //郵件完成處理 25 -(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ 27 [self dismissModalViewControllerAnimated:YES]; 29 if (result == MessageComposeResultCancelled) 30 NSLog(@"Message cancelled"); 31 else if (result == MessageComposeResultSent) 32 NSLog(@"Message sent"); 33 else 34 NSLog(@"Message failed"); 35 36 } 37
默認發送短信的界面爲英文的,解決辦法爲:在.xib 中的Localization添加一組chinese
1 [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 2 (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
1 -(void)checkboxClick:(UIButton *)btn 2 { 3 btn.selected = !btn.selected; 4 } 5 7 - (void)viewDidLoad { 8 UIButton *checkbox = [UIButton buttonWithType:UIButtonTypeCustom]; 10 CGRect checkboxRect = CGRectMake(135,150,36,36); 11 [checkbox setFrame:checkboxRect]; 12 13 [checkbox setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal]; 14 [checkbox setImage:[UIImage imageNamed:@"checkbox_on.png"] forState:UIControlStateSelected]; 15 16 [checkbox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside]; 17 [self.view addSubview:checkbox]; 18 }
應用程序的名稱和版本號等信息都保存在mainBundle的infoDictionary字典中,用下面代碼能夠取出來。
1 NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary]; 2 NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];//版本名稱 3 NSString*appName =[infoDict objectForKey:@"CFBundleDisplayName"];//app名稱
1 <p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"> 2 <span style="color: #703daa">NSString</span> 3 * versionShortString = [infoDict <span style="color: rgb(61, 29, 129);">objectForKey</span>: 4 <span style="color: #d12f1b">@"CFBundleShortVersionString"</span>];//標識應用程序發佈版本號 5 </p> 6 NSString*text =[NSString stringWithFormat:@"%@ %@",appName,versionNum, 7 <span style="font-family: Menlo; font-size: 11px; white-space: pre; ">versionShortString</span>];
此version 爲工程info下的Bundle version字段值:value能夠隨意定義。
CFBundleVersion,標識(發佈或未發佈)的內部版本號。這是一個單調增長的字符串,包括一個或多個時期分隔的整數。
CFBundleShortVersionString 標識應用程序的發佈版本號。該版本的版本號是三個時期分隔的整數組成的字符串。第一個整數表明重大修改的版本,如實現新的功能或重大變化的修訂。第二個整 數表示的修訂,實現較突出的特色。第三個整數表明維護版本。該鍵的值不一樣於「CFBundleVersion」標識。
圖片裏的 Version 對應的就是CFBundleShortVersionString (發佈版本號 如當前上架版本爲1.1.0 以後你更新的時候能夠改成1.1.1)
Build 對應的是 CFBundleVersion(內部標示,用以記錄開發版本的,每次更新的時候都須要比上一次高 如:當前版本是11 下一次就要大於11 好比 12,13 ....10000)
好比,若是咱們作一個播放視頻的功能時,想在播放的時候,不會自動進入屏保(黑屏)
只要在代碼里加入這一行:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
固然,在想要黑屏的時候還須要把它設置爲NO(好比視頻播放完畢時),否則屏幕會在此軟件運行下一直亮着。
表示在版本控制中,自上一次提交以來,文件作了修改。貌似只有在帶有版本控制的項目代碼中才會顯示。
屏幕旋轉一共有4個相關屬性(旋轉方向):
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
前兩個是橫屏時的狀態,後兩個是正常狀態(Portrait)和上下顛倒(UpsideDown)時的狀態。
【注意:Left和Right兩個左右模擬器旋轉時移動的方向正好是相反的,但移動後Home的方向,就以下圖所示】
具體見下圖:
其中涉及到兩個方法,在ViewController中默認會實現這個方法:
1 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 2 { 3 //除了不容許旋轉屏幕後:上下顛倒,其他方向都運行旋轉 4 //若是想都運行,能夠直接返回YES,或都不容許NO 5 return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 6 7 }
這 個方法是聲明此ViewController所運行屏幕旋轉的方向,一共4種類型,所有容許返回YES,上圖所示除了不容許上下顛倒,其他均可以。【注 意,項目設置Supported Device Orientations 所支持的屏幕旋轉類型並不影響此方法的設置,也就是說,哪怕Support只支持Portrait,方法裏設置UpsideDown,此 ViewController也會實現上下顛倒旋轉的】
第二個方法,是咱們比較經常使用的,也就是在設備即將以某個方向旋轉以前,咱們在其狀態(方向)設置組件或view的Frame,bound,等須要改變的屬性時所用到的方法。
1 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 2 //屏幕旋轉到橫屏時 4 if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 5 myMapview.frame = CGRectMake(0,0,480, 300); 6 } 7 //屏幕旋轉到豎屏時 8 else{//== else if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) 9 myMapview.frame = CGRectMake(0, 0, 320,460); 10 } 11 12 }
全部旋轉屏幕後須要改變組件尺寸屬性的設置均可以在這個方法裏面實現。
【注意,以上兩個方法,在最新的ios6貌似已經不提倡使用了,除非要適應舊設備,新的旋轉屏幕的相關方法能夠網絡搜索一下】
http://blog.csdn.net/zzfsuiye/article/details/8251060 IOS6屏幕旋轉詳解(自動旋轉、手動旋轉、兼容IOS6以前系統)
http://blog.csdn.net/huifeidexin_1/article/details/7826159 ios旋轉屏幕總結 詳細教程
http://blog.csdn.net/xiaoyun8822/article/details/8213738 Ios5(三)屏幕的旋轉和大小設置;
以上爲參考教程
1 Application windows are expected to have a root view controller at the end of application launch解決方法:在ios5以上版本,應用程序加載時,須要一個 root view controller ,因此須要編寫代碼_rootViewController = [[RootViewController alloc] init];self.window.rootViewController = _rootViewController;此問題大可能是在Xib或Storyboard下操做ViewController時不當心鏈接 RootViewController 的底層View所致使的,檢查刪除沒有做用的view鏈接線,或是Clean (Command+Shift+K),再運行。
情景再現:
我 們在storyboard的一個視圖裏添加了一個view1用做快捷功能導航;而後在對應的viewController裏實例化了一個Mapview的 地圖view2,大小是整個屏幕,這樣一來,就把咱們在storyboard中添加的view1覆蓋了,這個時候,咱們想把view1在地圖view2的 上面,該怎麼作?
簡而言之就是window中subview的交換。
首先經過:NSLog(@"subviews:%@",self.view.subviews); 這個咱們能夠看到當前下全部的subview(NSArray類型)以下圖所示:
能夠看到一共有3個view:UILabel 地圖view2,添加的view1
咱們如今要作的就是把後二者對調一下,因此在self.view 中尋找一下看有沒有replace相關的方法
就是這個方法,第一個參數是要進行調換的地圖view2,第二個參數是調換後顯示的view1。
[self.viewexchangeSubviewAtIndex:1 withSubviewAtIndex:2];
由於經過log打印,咱們已經知道Mapview在第一個下標的位置,view1在第二個下標的位置。
大功告成。記住這個方法:self.view exchangeSubviewAtIndex:withSubviewAtIndex:];
有的時候,咱們的視圖使用了Navigation Controller ,可是主界面(rootviewcontroller)或其它push進入的界面 想使用一個全屏的view,就是說,不顯示頂部的navigationBar,這個時候,就須要咱們來隱藏了。
1 //隱藏NavigationBar 2 -(void) viewWillAppear:(BOOL)animated{ 3 [self.navigationControllersetNavigationBarHidden:YES animated:YES]; //設置隱藏 4 5 [super viewWillAppear:animated]; 6 } 7 8 -(void) viewWillDisappear:(BOOL)animated{ 9 [self.navigationControllersetNavigationBarHidden:NO animated:YES]; 10 11 [super viewWillDisappear:animated]; 12 }
一、實現UITextFieldDelegate協議;
二、實現textField:shouldChangeCharactersInRange:replacementString:方法;
1 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ 2 int kMaxLength = 11; 3 4 NSInteger strLength = textField.text.length - range.length + string.length; 5 //輸入內容的長度 - textfield區域字符長度(通常=輸入字符長度)+替換的字符長度(通常爲0) 6 return (strLength <= kMaxLength); 7 8 }
如上代碼,若是咱們簡單的這樣寫: if(range.location<=11) return 或是 if (textfield.text.length>=11) 這樣雖然也能限制位數爲11位,
可是若是經過放大鏡把光標切換到以前的位數後,你照樣能夠輸入,而且還會致使輸入11位後,鍵盤上的退格(X鍵)沒法使用,緣由是:
咱們在location到達11位後,返回了NO,鍵盤沒法相應:添加,修改,刪除。這是很嚴重的。因此照着我上面的。
方法解讀:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
功能:
把textField中位置爲range的字符串替換爲string字符串;此函數在textField內容被修改時調用;
返回值:
YES,表示修改生效;NO,表示不作修改,textField的內容不變。
參數說明:
textField:響應UITextFieldDelegate協議的UITextField控件。
range: UITextField控件中光標選中的字符串,即被替換的字符串;
range.length爲0時,表示在位置range.location插入string。
string: 替換字符串; string.length爲0時,表示刪除。
1 UINib *nib = [UINib nibWithNibName:@"TvWeiboCell" bundle:nil]; 2 [tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
iphone APP圖標尺寸:57X57 高清:114X114 單位:pixel 命名:無特殊要求,最好是,app_icon 高清的要加@2x
iphone 啓動頁尺寸:大小最好是320X460或320X480(至關於整個屏幕尺寸) 單位:pixel 命名:Default.png
iPad APP圖標尺寸:72X72 高清:144X144 單位:pixel 命名:
ipad 啓動頁尺寸:大小最好是768X1004或768X1024 單位:pixel 命名:Default-Portrait~ipad.png 高清:Default-Portrait@2x~ipad.png
NSString 中的方法:
NSStringFromCGPoint
NSStringFromCGSize
NSStringFromCGRect
NSStringFromCGAffineTransform
NSStringFromUIEdgeInsets
如:NSLog(@"rect1: %@", NSStringFromCGRect(rect1));
如上圖所示,回退到界面2,很簡單: [self.navigationControllerpopViewControllerAnimated:YES]; 直接就回退到界面2了,但是咱們既不想回到rootviewcontroller,
也不想回到界面2,只想回到界面1,該如何作?
笨方法:在界面1要跳轉到界面2時,把本身self,set到界面2(前提界面2要設置一個id類型的屬性,用來存放界面1self,以此類推,當在界面3想退到界面1時,
[self.navigationControllerpopToViewController:controlleranimated:YES];
其實如今剛明白,一個很簡單的方法:
1 NSArray *viewControllers=[self.navigationController viewControllers]; 2 UIViewController *controller=[viewControllers objectAtIndex:1];
想起來navigation的機制了吧,每當咱們push到一個viewcontroller時,就會把這個viewcontroller的實例保存到nsarray裏,
經過array能夠獲取到任何一個viewcontroller,
這不就解決問題了麼?
[self.navigationController popToViewController:controller animated:YES];
【注意】千萬不要在這個地方實例化 界面1 而後popToViewController,這種方法是不對的。
新寫的App中須要使用UINavigationController對各個頁面進行導航,但因爲第一級頁面的title較長,在進入第二級頁面後返回按鈕
leftButtonItem的title就會變得很長,對NavigationBar空間佔用很大,並且不美觀,因而使用代碼對leftButtonItem的title文本進行修改,
不管是設置self.navigationItem.leftBarButtonItem.title = @"返回";仍是self.navigationItem.backBarButtonItem.title = @"返回";
都沒有效果,title文本始終不會發生變化。到網上亂搜一通後,獲得瞭如下解決方法,相對來講比較簡單,特記錄以下:
在第一級頁面的viewDidLoad方法中加入如下代碼:
1 UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init]; 2 temporaryBarButtonItem.title =@"返回"; 3 self.navigationItem.backBarButtonItem = temporaryBarButtonItem; 4 [temporaryBarButtonItem release]; 5 // 也就是用一個新的按鈕在進行導航前將原來的返回按鈕替換掉就能夠了。
因此,經過這個咱們能夠明白,self.navigationItem.backBarButtonItem是在一級頁面設置的(提早設置下一個頁面的返回按鈕),
而self.navigationItem.leftBarButtonItem/rightBarButton是在二級頁面設置的,(隨意設置本頁面的左右按鈕,左按鈕將替代系統的返回按鈕)
---------------------------------------------------------------------------------------------------------
通常一個程序中有一個UIWindow,一個UINavigationController,一個根UIViewController,多個子UIViewController。
UIWindow是整個可視界面的容器,裏面放置咱們看到的UIView。
UIView負責處理屏幕上一個矩形區域的繪製,UIView中還可包含子UIView。
UIWindow是UIView類的擴展,能夠看做是整個屏幕的根UIView。
UIViewController負責管理UIView的層次結構。能夠有多個UIViewController。
一個UIViewController中有一個頂部的UINavigationBar、一個根UIView,多個子UIView。
UINavigationBar中有一個UINavigationItem,UINavigationItem。
UINavigationController是用於構建分層應用程序的主要工具,它維護了一個UIViewController棧。
這個棧中必須有一個根UIViewController,其餘的UIViewController都是子UIViewController。
UINavigationItem表示UINavigationBar中的控件,好比左按鈕、中間標題、右按鈕。
UINavigationController會自動在當前子UIViewController的UINavigationBar左邊添加一個返回按鈕。
按鈕名稱是上一個UIViewController的標題。
---------------------------------------------------------------------------------------------------------
/**********************************************/
self.navigationItem
self.navigationController.navigationItem
self.navigationController.navigationBar
/**********************************************/
1, 不要混淆 self.navigationItem 和 self.navigationController.navigationItem ,
UINavigationItem 自己是用來 定製 ViewController本身在被導航過程當中的 appearence, navigationItem是UIViewController類
關於UINavigationControllerItem類別的擴展:
@interface UIViewController (UINavigationControllerItem)
@property(nonatomic,readonly,retain)UINavigationItem * navigationItem;
...
@end
因此後者 是調用 VC的所在的導航控制器導航控制器本身本身做爲VC的 navigationItem,是導航的疊加。
2. UINavigationBar 繼承於 UIView,隸屬於整個 UINavigationController ,用來定義整個導航過程當中的導航欄的顏色等其餘數值,
(相似於 self.tabBarController.tabBar UINavigationBar ,只須要一個設置通用的基本屬性),只能經過self.navigationController.navigationBar來訪問。
所以,定製於導航堆棧裏某個VC 的時候,通常經過self.navigationItem, 好比經常使用的self.navigationItem.leftBarButtonItem,
self.navigationItem.rightButtonItem, 同時若是本身來定製導航欄的外觀的話,就要用到self.navigationItem.titleView,
這個能夠直接用一個 CustomView 賦值於self.navigationItem.titleView便可。此時,若是須要,就得本身畫導航過程當中的返回按鈕了。
1
2 +(UIImage *)scale:(UIImage *)image toSize:(CGSize)size 3 { 4 UIGraphicsBeginImageContext(size); 5 [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; 6 UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 7 UIGraphicsEndImageContext(); 8 return scaledImage; 9 }
iOS 6中NSString對象有些新的使用方法,可讓字符串轉變成所有大寫,所有小寫,或者每一個單詞首字母大寫。
代碼以下所示:
1 NSString *str = @"mobile developer tips"; 2 // Convert string to uppercase 3 NSString *upperStr = [str uppercaseStringWithLocale:[NSLocale currentLocale]]; 4 NSLog(@"upperStr: %@", upperStr); 5 6 // Convert string to caps 7 NSString *capStr = [upperStr capitalizedStringWithLocale:[NSLocale currentLocale]]; 8 NSLog(@"capStr: %@", capStr); 9 10 // Convert string to lowercase 11 NSString *lowerStr = [capStr lowercaseStringWithLocale:[NSLocale currentLocale]]; 12 NSLog(@"lowerStr: %@", lowerStr);
運行結果:
雖然更改了新demo的bundle identifier和以前的identifier同樣,可是真機上還保留着以前調試時的demo,因此新的工程若是使用一樣的identifier真機調試,須要先把機器上原來的demo刪除,再使用新工程調試。
1 #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136),
[[UIScreen mainScreen] currentMode].size) : NO)
在須要判斷屏幕尺寸的地方:
mymapview = [[BMKMapView alloc] initWithFrame:CGRectMake(0,0,320,460+(iPhone5?88:0))];
iphone5的View爲568,減去Nav(44)+任務欄(20),爲504,相比iphone4s及之前版本的480,減去Nav+任務欄,爲416,高出88(差異).
http://www.cnblogs.com/maxfong/archive/2012/10/04/2711379.html
選中項目--target---build settings 找到C++Standard Library 改爲:Compiler Default,再編譯就不會有錯誤了.
首先要在工程里加入Audio Toolbox framework這個庫,而後在須要調用的文件裏
#import <AudioToolbox/AudioToolbox.h>
最後在須要播放提示音的地方編寫以下代碼:
AudioServicesPlaySystemSound(1000);//新郵件消息提示
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //震動
注:括號中爲系統聲音的id,詳見請參考如下網址http://iphonedevwiki.net/index.php/AudioServices。
http://blog.csdn.net/tskyfree/article/details/8096500
http://www.cnblogs.com/martin1009/archive/2012/06/14/2549473.html
http://www.cnblogs.com/chen1987lei/archive/2012/02/07/2341535.html
最好不要在UIViewController的loadView方法中改變狀態欄的可視性(好比狀態欄由顯示變爲隱藏、或者由隱藏變爲顯示),由於會致使重複調用2次loadView和viewDidLoad方法。
//錯誤代碼 1 - (void)loadView { 2 NSLog(@"loadView"); 3 // 隱藏狀態欄 4 [UIApplication sharedApplication].statusBarHidden = YES; 5 6 // .... 建立UIView 7 self.view = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease]; 8 self.view.backgroundColor = [UIColor grayColor]; 9 } 10 11 - (void)viewDidLoad { 12 [super viewDidLoad]; 13 NSLog(@"viewDidLoad"); 14 }
打印信息:
1 2013-05-14 00:51:36.152 test[2251:c07] loadView
2 2013-05-14 00:51:36.153 test[2251:c07] loadView
3 2013-05-14 00:51:36.153 test[2251:c07] viewDidLoad
4 2013-05-14 00:51:36.154 test[2251:c07] viewDidLoad
雖然運行效果是對的,可是系統連續調用了2次loadView和viewDidLoad方法,致使建立了2次UIView,形成了沒必要要的開銷。
緣由分析:
狀態欄由顯示變爲隱藏,意味着屏幕的可用高度變長了,UIViewController的UIView的高度也要從新調整,所以系統會從新調用
loadView方法建立UIView,建立完畢後再次調用viewDidLoad方法。