iPhone應用開發學習筆記

來源:互聯網
上載者:User

iPhone應用開發學習筆記是本文要介紹的內容,主要講解了iphone如何讀取txt檔案、利用WebView在ipad下實現滾動分頁效果、iPhone抓圖程式的內容,來看詳細內容。

iphone讀取txt檔案

讀取一般性文檔檔案 

 
  1. NSString *tmp;   
  2. NSArray *lines;    
  3. lines = [[NSString    stringWithContentsOfFile:@"testFileReadLines.txt"]   
  4.               componentsSeparatedByString:@"\n"];   
  5.  
  6. NSEnumerator *nse = [lines objectEnumerator];   
  7.  
  8. // 讀取<>裡的內容   
  9. while(tmp = [nse nextObject]) {   
  10.           NSString *stringBetweenBrackets = nil;   
  11.           NSScanner *scanner = [NSScanner scannerWithString:tmp];   
  12.           [scanner scanUpToString:@"<" intoString:nil];   
  13.           [scanner scanString:@"<" intoString:nil];   
  14.           [scanner scanUpToString:@">" intoString:&stringBetweenBrackets];   
  15.  
  16.           NSLog([stringBetweenBrackets description]);   
  17.   }  

利用WebView在ipad下實現滾動分頁效果

WebView裡面的網頁,滾動的時候預設是平滑滾動的,如果需要讓它實現分頁的滾動效果,那麼如何做?

預設UIWebView是沒有API提供的,但是在sdk3.2下,它的第一個子View是UIScrollView注意對於3.2之下的版本是UIScroller一個私人未公開的,這個暫時沒研究如何設定).

代碼相對比較簡單:

 
  1. int height = webView.frame.size.height;  
  2.  
  3. NSString *html = [NSString stringWithFormat:@"<html><head><style>div{height:%dpx;
  4. }
  5. </style></head><body style='margin:0px'><div style='background-color:#FF0000;'>
  6. </div><div style='background-color:#FFFF00;'></div><div style='background-color:#FF00FF;'>
  7. </div><div style='background-color:#0000FF;'></div><div style='background-color:#00FFFF;'>
  8. </div><div style='background-color:#00FF00;'></div></body></html>",  
  9.   height];  
  10.  
  11. [webView loadHTMLString:html baseURL:nil];  
  12. UIScrollView *scrollView = [webView.subviews objectAtIndex:0]; // it is "UIScroller" on iphone(v3.1.3-)  
  13. if (scrollView && [scrollView isKindOfClass:[UIScrollView class]]) {  
  14.     scrollView.pagingEnabled = YES;  
  15. }  

iPhone抓圖程式

//獲得螢幕映像

 
  1. - (UIImage *)imageFromView: (UIView *) theView    
  2. {  
  3.       
  4.     UIGraphicsBeginImageContext(theView.frame.size);  
  5.     CGContextRef context = UIGraphicsGetCurrentContext();  
  6.     [theView.layer renderInContext:context];  
  7.     UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();  
  8.     UIGraphicsEndImageContext();  
  9.       
  10.     return theImage;  

//獲得某個範圍內的螢幕映像

 
  1. - (UIImage *)imageFromView: (UIView *) theView   atFrame:(CGRect)r  
  2. {  
  3.     UIGraphicsBeginImageContext(theView.frame.size);  
  4.     CGContextRef context = UIGraphicsGetCurrentContext();  
  5.     CGContextSaveGState(context);  
  6.     UIRectClip(r);  
  7.     [theView.layer renderInContext:context];  
  8.     UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();  
  9.     UIGraphicsEndImageContext();  
  10.       
  11.     return  theImage;//[self getImageAreaFromImage:theImage atFrame:r];  

小結:iPhone應用開發學習筆記的內容介紹完了,希望本文對你有所協助!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.