IPhone Application Development Study Notes

Source: Internet
Author: User

IPhoneThe Application Development Study Notes are described in this article.IphoneHow to read txtFileUse WebView to implement scrolling paging effect on ipad,IPhoneThe content of the screenshot program.

Iphone reads txt files

Read general document files

 
 
  1. NSString * tmp;
  2. NSArray * lines;
  3. Lines = [[NSString stringWithContentsOfFile: @ "testFileReadLines.txt"]
  4. ComponentsSeparatedByString: @ "\ n"];
  5.  
  6. NSEnumerator * neuron = [lines objectEnumerator];
  7.  
  8. // Read the content in <>
  9. While (tmp = [neuron nextObject]) {
  10. NSString * stringBetweenBrackets = nil;
  11. Ns‑* token = [ns‑scannerwithstring: tmp];
  12. [Export scanUpToString: @ "<" Export string: nil];
  13. [Export scanString: @ "<" Export string: nil];
  14. [Export scanUpToString: @ ">" Export string: & stringBetweenBrackets];
  15.  
  16. NSLog ([stringBetweenBrackets description]);
  17. }

Use WebView to implement scrolling paging effect on ipad

Web pages in WebView are smoothly rolled by default during scrolling. If you want to implement paging scrolling, what should you do?

By default, UIWebView is not provided by APIs. However, in sdk3.2, its first sub-View is UIScrollView. Note that for versions earlier than 3.2, UIScroller is private and undisclosed, I have not studied how to set this ).

The code is relatively simple:

 
 
  1. int height = webView.frame.size.height;  
  2.  
  3. NSString *html = [NSString stringWithFormat:@"
  4. }
  5. </style>
  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>
  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 image capture program

// ObtainScreenImage

 
 
  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;  

// ObtainScreenImage

 
 
  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];  

Summary:IPhoneThe content of the Application Development Study Notes has been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.