本文原始地址:IOS 5新增API介紹及使用
1.UIStepper
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(200, 100, 0, 0)]; [stepper sizeToFit]; stepper.value = 0; stepper.minimumValue = 0; stepper.maximumValue = 1; stepper.stepValue = 0.1; [stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:stepper]; [stepper release];
- (void)stepperAction:(UIStepper *)stepper{ NSLog(@"stepper value:%f",stepper.value);}
2.UIAlertView樣式
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"Hello World" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];//第一張圖 alert.alertViewStyle = UIAlertViewStylePlainTextInput;//第二張圖 alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;//第三張圖 alert.alertViewStyle = UIAlertViewStyleSecureTextInput; [alert show]; [alert release];
//返回指定索引值的TextField ,這個API僅存在於IOS5.0以上- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex{ return textField;}
3 UIScreen調節亮度
UIScreen *mainScreen = [UIScreen mainScreen]; //設定螢幕亮度為50% mainScreen.brightness = 0.5; //預設是NO。如果YES,可以通過wantsSoftwareDimming屬性來聲明此應用需要將螢幕亮度調整到比中等亮度偏暗的層級。(需要注意的是,開啟wantsSoftwareDimming可能會對效能有影響,因為這種昏暗是通過軟體來實現的。) mainScreen.wantsSoftwareDimming = YES;
4 UIReferenceLibraryViewController顯示詞語解釋
NSString *key = @"hello"; //判斷任何已經安裝的字典裡有key的定義 if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:key]) { UIReferenceLibraryViewController *controller = [[UIReferenceLibraryViewController alloc] initWithTerm:key]; //只是切換方式 [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; [self presentModalViewController:controller animated:YES]; [controller release]; }
5.UISplitViewController delegate,顯示隱藏時delegate
UISplitViewController
//這個delegate方法是被發送到你的delegate詢問在特定方向下你想要左側做什麼,因此它把自己傳遞給你,還有左側,它會問在這個方向你想要我對左側做什麼。要隱藏就返回YES,要保留在螢幕上就返回NO- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation{ return YES;}
6.從xib檔案中擷取cell建立UITableViewCell
//為tableview註冊一個nib UINib *nib = [UINib nibWithNibName:@"MyCell" bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:@"identifier"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //重用前面註冊過的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];//other codereturn cell;}
7 UIImage,image動畫
8 UIAppearance應用於全部屬性IOS 5下強大的UI修改工具—— UIAppearance
//程式中所有slider改為紅色 [[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]];
9 UIPageViewControllerUIPageViewController-淺析控制項為我們提供了一種像翻書效果的一種控制項。我們可以通過使用UIPageViewController控制項,來完成類似圖書一樣的翻頁控制方式。
10 UIDocumentiPhone開發 - iCloud開發準備
支援iCloud簡記
11 管理資產庫ALAssetsLibrary-代碼操作iOS相簿資源
ALAssetsLibrary提供了我們對iOS裝置中的相片、視頻的訪問。
可以通過valueForProperty擷取到圖片的資訊,包括類型, Location , 時間長度,方向,日期,格式 , URL地址。
self.view.backgroundColor = [UIColor whiteColor]; self.assetsLibrary = [[ALAssetsLibrary alloc] init]; dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(dispatchQueue, ^(void) { // 遍曆所有相簿 [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { // 遍曆每個相簿中的項ALAsset [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,BOOL *stop) { __block BOOL foundThePhoto = NO; if (foundThePhoto) { *stop = YES; } // ALAsset的類型 NSString *assetType = [result valueForProperty:ALAssetPropertyType]; //如果是照片的話 //ALAssetTypeVideo //ALAssetTypeUnknown if ([assetType isEqualToString:ALAssetTypePhoto]) { foundThePhoto = YES; *stop = YES; //封裝了ALAsset,包含了一個資源檔中的很多屬性。(可以說是ALAsset的不同的表示方式,本質上都表示同一個資源檔) ALAssetRepresentation *assetRepresentation = [result defaultRepresentation]; CGFloat imageScale = [assetRepresentation scale]; UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation]; dispatch_async(dispatch_get_main_queue(), ^(void) { CGImageRef imageReference = [assetRepresentation fullResolutionImage]; // 對找到的圖片進行操作 UIImage *image = [[UIImage alloc] initWithCGImage:imageReference scale:imageScale orientation:imageOrientation]; if (image != nil) { //呈現 self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; self.imageView.contentMode = UIViewContentModeScaleAspectFit; self.imageView.image = image; [self.view addSubview:self.imageView]; } else { NSLog(@"Failed to create the image."); } }); } }]; } failureBlock:^(NSError *error) { //讀取失敗的處理 }]; });
12 GLKit如何為iOS5建立一個簡單GLKit應用程式
13 Core ImageiOS5新特性:強大的Core Image
14 Core Data[Cocoa]深入淺出 Cocoa 之 Core Data(1)- 架構詳解