iPhone應(yīng)用開發(fā)學(xué)習(xí)筆記
iPhone應(yīng)用開發(fā)學(xué)習(xí)筆記是本文要介紹的內(nèi)容,主要講解了iphone如何讀取txt文件、利用WebView在ipad下實(shí)現(xiàn)滾動分頁效果、iPhone抓圖程序的內(nèi)容,來看詳細(xì)內(nèi)容。
iphone讀取txt文件
讀取一般性文檔文件
- NSString *tmp;
- NSArray *lines;
- lines = [[NSString stringWithContentsOfFile:@"testFileReadLines.txt"]
- componentsSeparatedByString:@"\n"];
- NSEnumerator *nse = [lines objectEnumerator];
- // 讀取<>里的內(nèi)容
- 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下實(shí)現(xiàn)滾動分頁效果
WebView里面的網(wǎng)頁,滾動的時(shí)候默認(rèn)是平滑滾動的,如果需要讓它實(shí)現(xiàn)分頁的滾動效果,那么如何做?
默認(rèn)UIWebView是沒有API提供的,但是在sdk3.2下,它的***個(gè)子View是UIScrollView(注意對于3.2之下的版本是UIScroller一個(gè)私有未公開的,這個(gè)暫時(shí)沒研究如何設(shè)置).
代碼相對比較簡單:
- 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;
- }
//獲得某個(gè)范圍內(nèi)的屏幕圖像
- - (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];
- }
小結(jié):iPhone應(yīng)用開發(fā)學(xué)習(xí)筆記的內(nèi)容介紹完了,希望本文對你有所幫助!