iPhone应用开发学习笔记

移动开发 iOS
本文主要讲解了iphone如何读取txt文件、利用WebView在ipad下实现滚动分页效果、iPhone抓图程序的内容,来看详细内容。

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应用开发学习笔记的内容介绍完了,希望本文对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2011-08-08 14:57:46

iPhone Autoreleas Property

2011-08-12 09:48:24

iPhoneCoreLocatio定位

2011-08-19 11:10:31

iPhone应用

2011-08-15 10:06:22

iPhone开发nib 文件

2011-08-08 10:10:14

iPhone开发 图片 方法

2011-08-18 10:39:46

iPhone开发界面

2011-08-05 14:48:06

iPhone应用 异步队列

2011-08-08 15:56:18

iPhone 震动 NSUserDefa

2011-08-15 17:38:48

iPhone开发调试工具

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-07-27 11:14:37

iPhone UITableVie

2011-08-15 18:02:32

iPhone开发表视图

2011-08-15 17:52:21

iPhone应用对象NSString

2011-08-16 18:13:42

IPhone开发UIView动画

2011-08-19 09:49:03

iPhone开发Three20 NetTTRequestLo

2011-07-27 10:13:23

Cocos2D iPhone

2011-08-08 16:56:44

iPhone 字符处理 视图

2011-08-10 10:10:21

iPhoneUIPopoverCo

2011-07-19 09:58:36

2011-07-19 09:46:38

点赞
收藏

51CTO技术栈公众号