偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iPhone開發(fā)常用代碼集錦

移動開發(fā) iOS
iPhone開發(fā)常用代碼集錦是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)iphone開發(fā)中的一些小實(shí)例的實(shí)現(xiàn),具體參考本文詳細(xì)內(nèi)容講解,一起來看內(nèi)容。

iPhone開發(fā)常用代碼集錦是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)iphone開發(fā)中的一些小實(shí)例的實(shí)現(xiàn),具體參考本文詳細(xì)內(nèi)容講解,一起來看內(nèi)容。

更改cell選中的背景

  1. UIView *myview = [[UIView alloc] init];  
  2. myview.frame = CGRectMake(0, 0, 320, 47);  
  3. myview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"0006.png"]];  
  4. cell.selectedBackgroundView = myview

在數(shù)字鍵盤上添加button:

  1. //定義一個消息中心  
  2. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
  3. //addObserver:注冊一個觀察員 name:消息名稱  
  4. - (void)keyboardWillShow:(NSNotification *)note {  
  5.     // create custom button  
  6.     UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];  
  7.     doneButton.frame = CGRectMake(0, 163, 106, 53);  
  8.     [doneButton setImage:[UIImage imageNamed:@"5.png"] forState:UIControlStateNormal];  
  9.     [doneButton addTarget:self action:@selector(addRadixPoint) forControlEvents:UIControlEventTouchUpInside];  
  10.      
  11.     // locate keyboard view  
  12.     UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];//返回應(yīng)用程序window  
  13.     UIView* keyboard;  
  14.     for(int i=0; i<[tempWindow.subviews count]; i++) //遍歷window上的所有subview  
  15.     {  
  16.         keyboard = [tempWindow.subviews objectAtIndex:i];  
  17.         // keyboard view found; add the custom button to it  
  18.         if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)  
  19.         [keyboard addSubview:doneButton];  
  20.     }  

正則表達(dá)式使用:

被用于正則表達(dá)式的字串必須是可變長的,不然會出問題

將一個空間放在視圖之上

  1. [scrollView insertSubview:searchButton aboveSubview:scrollView]; 

從本地加載圖片

  1. NSString *boundle = [[NSBundle mainBundle] resourcePath];  
  2. [web1 loadHTMLString:[NSString stringWithFormat:@"<img src='0001.png'/>"] baseURL:[NSURL fileURLWithPath:boundle]]; 

從網(wǎng)頁加載圖片并讓圖片在規(guī)定長寬中縮小

  1. [cell.img loadHTMLString:[NSString stringWithFormat:@"<html><body><img src='%@' height='90px' width='90px'></body></html>",
  2. goodsInfo.GoodsImg] baseURL:nil]; 

將網(wǎng)頁加載到webview上通過javascript獲取里面的數(shù)據(jù),如果只是發(fā)送了一個連接請求獲取到源碼以后可以用正則表達(dá)式進(jìn)行獲取數(shù)據(jù)

  1. NSString *javaScript1 = @"document.getElementsByName('.u').item(0).value";  
  2. NSString *javaScript2 = @"document.getElementsByName('.challenge').item(0).value";  
  3. NSString *strResult1 = [NSString stringWithString:[theWebView stringByEvaluatingJavaScriptFromString:javaScript1]];  
  4. NSString *strResult2 = [NSString stringWithString:[theWebView stringByEvaluatingJavaScriptFromString:javaScript2]]; 

用NSString怎么把UTF8轉(zhuǎn)換成unicode

  1. utf8Str //  
  2. NSString *unicodeStr = [NSString stringWithCString:[utf8Str UTF8String] encoding:NSUnicodeStringEncoding]; 

View自己調(diào)用自己的方法:

  1. [self performSelector:@selector(loginToNext) withObject:nil afterDelay:2];//黃色段為方法名,和延遲幾秒執(zhí)行. 

顯示圖像:

  1. CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);  
  2. UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];  
  3. [myImage setImage:[UIImage imageNamed:@"myImage.png"]];  
  4. myImage.opaque = YES; //opaque是否透明  
  5. [self.view addSubview:myImage];  
  6. [myImage release];  
  7.  
  8. WebView:  
  9. CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);  
  10. UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];  
  11. [webView setBackgroundColor:[UIColor whiteColor]];  
  12. NSString *urlAddress = @"http://www.google.com";  
  13. NSURL *url = [NSURL URLWithString:urlAddress];  
  14. NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];  
  15. [webView loadRequest:requestObj];  
  16. [self addSubview:webView];  
  17. [webView release]; 

顯示網(wǎng)絡(luò)活動狀態(tài)指示符

這是在iPhone左上部的狀態(tài)欄顯示的轉(zhuǎn)動的圖標(biāo)指示有背景發(fā)生網(wǎng)絡(luò)的活動。

  1. UIApplication* app = [UIApplication sharedApplication];  
  2. app.networkActivityIndicatorVisible = YES

動畫:一個接一個地顯示一系列的圖象

  1. NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"myImage1.png"], [UIImage imageNamed:@"myImage2.png"],
  2.  [UIImage imageNamed:@"myImage3.png"], [UIImage imageNamed:@"myImage4.gif"], nil];  
  3. UIImageView *myAnimatedView = [UIImageView alloc];  
  4. [myAnimatedView initWithFrame:[self bounds]];  
  5. myAnimatedView.animationImages = myImages; //animationImages屬性返回一個存放動畫圖片的數(shù)組  
  6. myAnimatedView.animationDuration = 0.25; //瀏覽整個圖片一次所用的時間  
  7. myAnimatedView.animationRepeatCount = 0; // 0 = loops forever 動畫重復(fù)次數(shù)  
  8. [myAnimatedView startAnimating];  
  9. [self addSubview:myAnimatedView];  
  10. [myAnimatedView release]; 

動畫:顯示了something在屏幕上移動。注:這種類型的動畫是“開始后不處理” -你不能獲取任何有關(guān)物體在動畫中的信息(如當(dāng)前的位置) 。如果您需要此信息,您會手動使用定時器去調(diào)整動畫的X和Y坐標(biāo)

這個需要導(dǎo)入QuartzCore.framework

  1. CABasicAnimation *theAnimation;  
  2. theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];  
  3. //Creates and returns an CAPropertyAnimation instance for the specified key path.  
  4. //parameter:the key path of the property to be animated  
  5. theAnimation.duration=1;  
  6. theAnimation.repeatCount=2;  
  7. theAnimation.autoreverses=YES;  
  8. theAnimation.fromValue=[NSNumber numberWithFloat:0];  
  9. theAnimation.toValue=[NSNumber numberWithFloat:-60];  
  10. [view.layer addAnimation:theAnimation forKey:@"animateLayer"];  
  11. Draggable items//拖動項(xiàng)目  
  12. Here's how to create a simple draggable image.//這是如何生成一個簡單的拖動圖象 

1. Create a new class that inherits from UIImageView

  1. @interface myDraggableImage : UIImageView { } 

2. In the implementation for this new class, add the 2 methods:

  1. - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event  
  2. {  
  3. // Retrieve the touch point 檢索接觸點(diǎn)  
  4. CGPoint pt = [[touches anyObject] locationInView:self];  
  5. startLocation = pt;  
  6. [[self superview] bringSubviewToFront:self];  
  7. }  
  8. - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event  
  9. {  
  10. // Move relative to the original touch point 相對以前的觸摸點(diǎn)進(jìn)行移動  
  11. CGPoint pt = [[touches anyObject] locationInView:self];  
  12. CGRect frame = [self frame];  
  13. frame.origin.x += pt.x - startLocation.x;  
  14. frame.origin.y += pt.y - startLocation.y;  
  15. [self setFrame:frame];  

3. Now instantiate the new class as you would any other new image and add it to your view

  1. //實(shí)例這個新的類,放到你需要新的圖片放到你的視圖上  
  2. dragger = [[myDraggableImage alloc] initWithFrame:myDragRect];  
  3. [dragger setImage:[UIImage imageNamed:@"myImage.png"]];  
  4. [dragger setUserInteractionEnabled:YES]; 

線程:

1. Create the new thread:

  1. [NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil]; 

2. Create the method that is called by the new thread:

  1. - (void)myMethod  
  2. {  
  3. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
  4. *** code that should be run in the new thread goes here ***  
  5. [pool release];  
  6. }  
  7. //What if you need to do something to the main thread from inside your new thread (for example, 
  8. show a loading //symbol)? Use performSelectorOnMainThread.  
  9. [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false]; 

Plist files

  1. Application-specific plist files can be stored in the Resources folder of the app bundle. 
  2. When the app first launches, it should check if there is an existing plist in the user's Documents folder, 
  3. and if not it should copy the plist from the app bundle.  
  4. // Look in Documents for an existing plist file  
  5. NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);  
  6. NSString *documentsDirectory = [paths objectAtIndex:0];  
  7. myPlistPath = [documentsDirectory stringByAppendingPathComponent:  
  8. [NSString stringWithFormat: @"%@.plist", plistName] ];  
  9. [myPlistPath retain];  
  10. // If it's not there, copy it from the bundle  
  11. NSFileManager *fileManger = [NSFileManager defaultManager];  
  12. if ( ![fileManger fileExistsAtPath:myPlistPath] )  
  13. {  
  14. NSString *pathToSettingsInBundle = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];  
  15. }  
  16. //Now read the plist file from Documents  
  17. NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);  
  18. NSString *documentsDirectoryPath = [paths objectAtIndex:0];  
  19. NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:@"myApp.plist"];  
  20. NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile: path];  
  21. //Now read and set key/values  
  22. myKey = (int)[[plist valueForKey:@"myKey"] intValue];  
  23. myKey2 = (bool)[[plist valueForKey:@"myKey2"] boolValue];  
  24. [plist setValue:myKey forKey:@"myKey"];  
  25. [plist writeToFile:path atomically:YES]; 

Alerts

  1. Show a simple alert with OK button.  
  2. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:  
  3. @"An Alert!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];  
  4. [alert show];  
  5. [alert release]; 

Info button

  1. Increase the touchable area on the Info button, so it's easier to press.  
  2. CGRect newInfoButtonRect = CGRectMake(infoButton.frame.origin.x-25,   
  3. infoButton.frame.origin.y-25, infoButton.frame.size.width+50, infoButton.frame.size.height+50);  
  4. [infoButton setFrame:newInfoButtonRect]; 

Detecting Subviews

  1. You can loop through subviews of an existing view. This works especially well if you use the "tag" property on your views.  
  2. for (UIImageView *anImage in [self.view subviews])  
  3. {  
  4. if (anImage.tag == 1)  
  5.         { // do something }  

小結(jié):iPhone開發(fā)常用代碼集錦的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你 有所幫助!

責(zé)任編輯:zhaolei 來源: 網(wǎng)易博客
相關(guān)推薦

2011-07-29 14:48:48

iPhone開發(fā)

2011-08-09 14:54:29

iPhoneNSDateanotherDate

2011-08-11 15:23:04

iPhoneNSBundleXcode

2010-08-11 09:51:28

Flex代碼

2010-09-07 10:20:21

CSS

2010-08-13 13:14:09

Flex圖表

2011-08-16 10:45:25

iPhone開發(fā)控件

2011-07-27 11:19:33

iPhone UITableVie

2011-08-08 15:05:50

iPhone 網(wǎng)站

2011-07-25 14:44:41

iPhone iPhone開發(fā) 截屏

2012-03-06 16:57:40

jQuery mobijQuery mobiframework

2018-05-10 15:35:03

前端代碼圖像

2017-10-17 09:55:16

數(shù)據(jù)庫SQL Server規(guī)范集錦

2015-07-22 17:32:22

mysql常用命令

2013-07-23 07:24:57

iOS開發(fā)學(xué)習(xí)iOS開發(fā)問題集錦

2011-07-06 17:53:40

iPhone SDK Xcode

2011-08-01 15:17:17

iPhone開發(fā) 證書 簽名

2011-08-01 13:13:19

iPhone開發(fā) 圖片

2011-08-15 11:23:41

iPhone開發(fā)循環(huán)滾動UIScrollVie

2010-08-31 14:01:23

iPhone
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號