iPhone應用開發(fā)學習筆記
iPhone應用開發(fā)學習筆記是本文要介紹的內容,主要講解了iphone如何讀取txt文件、利用WebView在ipad下實現(xiàn)滾動分頁效果、iPhone抓圖程序的內容,來看詳細內容。
iphone讀取txt文件
讀取一般性文檔文件
- NSString *tmp;
- NSArray *lines;
- lines = [[NSString stringWithContentsOfFile:@"testFileReadLines.txt"]
- componentsSeparatedByString:@"\n"];
- NSEnumerator *nse = [lines objectEnumerator];
- // 讀取<>里的內容
- while(tmp = [nse nextObject]) {
- NSString *stringBetweenBrackets = nil;
- NSScanner *scanner = [NSScanner scannerWithString:tmp];
- [scanner scanUpToString:@"<" intoString:nil];
- [scanner scanString:@"<" intoString:nil];
- [scanner scanUpToString:@">" intoString:&stringBetweenBrackets];
- NSLog([stringBetweenBrackets description]);
- }
利用WebView在ipad下實現(xiàn)滾動分頁效果
WebView里面的網頁,滾動的時候默認是平滑滾動的,如果需要讓它實現(xiàn)分頁的滾動效果,那么如何做?
默認UIWebView是沒有API提供的,但是在sdk3.2下,它的***個子View是UIScrollView(注意對于3.2之下的版本是UIScroller一個私有未公開的,這個暫時沒研究如何設置).
代碼相對比較簡單:
- int height = webView.frame.size.height;
- NSString *html = [NSString stringWithFormat:@"<html><head><style>div{height:%dpx;
- }
- </style></head><body style='margin:0px'><div style='background-color:#FF0000;'>
- </div><div style='background-color:#FFFF00;'></div><div style='background-color:#FF00FF;'>
- </div><div style='background-color:#0000FF;'></div><div style='background-color:#00FFFF;'>
- </div><div style='background-color:#00FF00;'></div></body></html>",
- height];
- [webView loadHTMLString:html baseURL:nil];
- UIScrollView *scrollView = [webView.subviews objectAtIndex:0]; // it is "UIScroller" on iphone(v3.1.3-)
- if (scrollView && [scrollView isKindOfClass:[UIScrollView class]]) {
- scrollView.pagingEnabled = YES;
- }
iPhone抓圖程序
//獲得屏幕圖像
- - (UIImage *)imageFromView: (UIView *) theView
- {
- UIGraphicsBeginImageContext(theView.frame.size);
- CGContextRef context = UIGraphicsGetCurrentContext();
- [theView.layer renderInContext:context];
- UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return theImage;
- }
//獲得某個范圍內的屏幕圖像
- - (UIImage *)imageFromView: (UIView *) theView atFrame:(CGRect)r
- {
- UIGraphicsBeginImageContext(theView.frame.size);
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextSaveGState(context);
- UIRectClip(r);
- [theView.layer renderInContext:context];
- UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return theImage;//[self getImageAreaFromImage:theImage atFrame:r];
- }
小結:iPhone應用開發(fā)學習筆記的內容介紹完了,希望本文對你有所幫助!