iOS開發之NavBar和TarBar使用技巧
1 改變NavBar顏色:選中Navigation Bar 的Tint屬性。選中顏色。
2 隱藏“back”按鈕: self.navigationItem.hidesBackButton = YES;
3 隱藏”NavBar” : self.navigationController.navigationBarHidden = YES;
4 可以不用MainWindow.xib建立的Navigation。在每個view上自定義。
需要把每個控制頁都加上以下程式碼來隱藏nav:
-(void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBarHidden = YES;//顯示"NavBar" }
然後在每個控制頁xib自己新增Navigation Bar。新增所需BarButtonItem按鈕。
5 頁面跳轉隱藏tarbar :
HomeDetailViewController *detailview = [[HomeDetailViewController alloc] initWithNibName:@"HomeDetailView" bundle:nil]; detailview.hidesBottomBarWhenPushed = YES;//隱藏tarbar [self.navigationController pushViewController:detailview animated:YES]; [detailview release];
6 頁面返回:
[self.navigationController popViewControllerAnimated:YES];
7 預設選中tabbar為第一個view:
TabBarController.selectedIndex= 0;
其他:
8 已知兩地經緯度 計算兩地之間的距離: // 地圖顯示當前位置: mapView.showsUserLocation=YES; CLLocationManager *locationManager = [[CLLocationManager alloc] init];//建立位置管理器 locationManager.delegate=self;//設定代理 locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度級別為最佳精度 locationManager.distanceFilter=1000.0f;//設定距離篩選器為任何移動都要傳送更新 [locationManager startUpdatingLocation];//啟動位置管理器 MKCoordinateSpan theSpan; //地圖的範圍 越小越精確 theSpan.latitudeDelta=0.05; theSpan.longitudeDelta=0.05; MKCoordinateRegion theRegion; theRegion.center=[[locationManager location] coordinate]; theRegion.span=theSpan; [mapView setRegion:theRegion]; [locationManager release]; MKUserLocation *usrLoc=mapView.userLocation; CLLocationCoordinate2D usrCoordinate=usrLoc.location.coordinate; NSLog(@"la==%f lo==%f",usrCoordinate.latitude,usrCoordinate.longitude); // 已知兩點的經緯度,計算出兩地距離: CLLocation *location1 = [[[CLLocation alloc] initWithLatitude:usrCoordinate.latitude longitude:usrCoordinate.longitude] autorelease]; CLLocation *location2 = [[[CLLocation alloc] initWithLatitude:36.676445 longitude:117.106793] autorelease]; NSLog(@"JULI====%.0f km", [location1 distanceFromLocation:location2]);//4502
9 取小數點後兩位(四捨五入),輸出:
NSLog(@”%.02f km”,4478.442312);
10 呼叫打電話API :
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10010"]];
使用這種方式撥打電話時,當使用者結束通話後,iphone介面會停留在電話介面。
用如下方式,可以使得使用者結束通話後自動返回到應用:
UIWebView*callWebview =[[UIWebView alloc] init]; NSURL *telURL =[NSURL URLWithString:@"tel:10086"];// 貌似tel:// 或者 tel: 都行 [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]]; //記得新增到view上 [self.view addSubview:callWebview];
11 呼叫 SMS發簡訊:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://15315310992"]];
12 呼叫自帶 瀏覽器 safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]];
13 在一個程式裡開啟另一個程式:
首先:plist裡新增URL types 點開裡邊的Item0 新增URLSchemes 開啟Item0 輸入sinaWeibo
然後在需要呼叫的地方:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sinaWeibo://*"]];
https://itunes.apple.com/cn/app/qq-2012/id444934666?mt=8
14 雙引號轉義:
用 \” 表示 雙引號
15 設定按鈕按下換圖片 鬆開還是原圖
// [danxuan setImage:[UIImage imageNamed:@"exercise_option_n.png"] forState:UIControlStateNormal]; //這個是設定按下的圖片,鬆開就是上面的圖片 // [danxuan setImage:[UIImage imageNamed:@"exercise_option_s.png"] forState:UIControlEventTouchDragOutside];
16 判斷陣列中是否存在某元素:
BOOL isValue=[keyArray containsObject:@"aaa"];
17 Nav新增button
UIButton *btnBack = [ABUtil createNavigationCtrollerRoundedRectBtn:Localized(@"取消")]; [btnBack addTarget:self action:@selector(tapLeftBarButton) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack]; self.navigationItem.leftBarButtonItem = leftBarButtonItem; [btnBack release]; [leftBarButtonItem release]
相關文章
- iOS開發之XLForm的使用iOSORM
- iOS開發之UIRefreshControl使用踩坑iOSUI
- iOS開發之使用Git的基本使用(二)iOSGit
- iOS開發之使用Git的基本使用(一)iOSGit
- iOS開發小技巧合集iOS
- [iOS開發]Carthage安裝和使用教程iOS
- iOS UIPickerView使用技巧iOSUIView
- iOS AutoLayout使用技巧iOS
- iOS開發之FuckingBlockSyntax!iOSBloC
- web元件之導航條(Bootstrap navbar)Web元件boot
- iOS開發之逆向工程iOS
- iOS之Wifi開發探究iOSWiFi
- 開發小技巧之:unicode的排序和正則匹配Unicode排序
- iOS開發中使用OC和swift的對比iOSSwift
- iOS開發之 Autolayout 詳解iOS
- iOS開發之彈窗管理iOS
- iOS高階開發者面試必過技巧iOS面試
- iOS開發常用小技巧記錄(持續更新)iOS
- Flutter 和iOS 混合開發(一)FlutteriOS
- ionic開發環境搭建之ios開發環境iOS
- Vue 開發之插槽(slot)的理解和使用Vue
- Android工程常用配置和開發技巧Android
- Flask開發技巧之異常處理Flask
- Flask開發技巧之引數校驗Flask
- ArcObjects SDK開發 024開發的技術和技巧Object
- iOS開發實用軟體之NWPusheriOS
- iOS開發之OC篇(3)—— NSArray、NSMutableArrayiOS
- iOS開發之 Method Swizzling 深入淺出iOS
- iOS開發之登入與訪客iOS
- iOS開發Settings.bundle的使用iOS
- Python開發技巧-使用Python生成HTML表格PythonHTML
- Linux之history使用技巧Linux
- iOS開發之返回指定的控制器iOS
- iOS開發之記憶體與快取iOS記憶體快取
- 關於iOS開發中copy的使用iOS
- iOS開發-UITabbarController的介紹與使用iOSUItabBarController
- iOS 開發iOS
- JavaWeb開發技巧之裝飾器設計模式JavaWeb設計模式
- 13個VSCode使用技巧,開啟高效的開發模式VSCode模式