iPhone应用开发学习笔记是本文要介绍的内容,主要讲解了iphone如何读取txt文件、利用WebView在ipad下实现滚动分页效果、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下实现滚动分页效果
WebView里面的网页,滚动的时候默认是平滑滚动的,如果需要让它实现分页的滚动效果,那么如何做?
默认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应用开发学习笔记的内容介绍完了,希望本文对你有所帮助!