IPhone application development example

Source: Internet
Author: User

IPhoneThe application development instance is described in this article.Character Processing, NavigationItem addView,Image. Not to mention, Let's first look at the details.

Special characters for data upload using NSURLConnection Post

A strange problem found during NSURLConnection Post upload. If it is a plus sign (+), it will be replaced with a space. For example, "google +" will become "google". The Code is as follows:

 
 
  1. NSString * bodyStr = @ "google + ";
  2. [UrlRequestsetHTTPBody: [bodyStr dataUsingEncoding: NSUTF8StringEncoding];
  3. // NSUTF8StringEncoding encoding is used to prevent errors during Chinese upload.

Check the information and find that the problem can be solved as long as these special symbols are UTF8 encoded before conversion. The Code is as follows:

 
 
  1. NSString*bodyStr =@"google+";  
  2. NSString*bStr =CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,   
  3.                                                        (CFStringRef)bodyStr,   
  4.                                                        NULL,   
  5.                                                CFSTR(":/?#[]@!$&’()*+,;="),   
  6.                                                kCFStringEncodingUTF8);  
  7. [urlRequest setHTTPBody:[bStr dataUsingEncoding:NSUTF8StringEncoding]];  
  8. [bStr release]; 

How to add a title view to NavigationItem

The navigator is often used in iOS application development. It is easy to add a title to the navigator. The syntax is as follows:

 
 
  1. self.title=@"Elimination phase Day 1"; 

However, if the question is too long and the second half becomes a ellipsis, You need to customize the font. The code and effect are as follows:

 
 
  1. UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 200, 20)];   
  2.     titleText.backgroundColor = [UIColor clearColor];   
  3.     [titleText setFont:[UIFont systemFontOfSize:15.0]];   
  4.     [titleText setText:@"Elimination phase Day 1"];   
  5.     self.navigationItem.titleView=titleText;   
  6.     [titleText release]; 

How to restore png images in an iPhone application

Apple specially processes png images in iPhone applications. A non-standard CgBI data segment is added after the png file header, And the IDAT image data segment does not have a traditional compressed data header or tail, in addition, red and blue are reversed, so that they cannot be used normally on Mac or Windows.

Foreign developers have fixed this issue. First download this program: http://acquisition.dreamhosters.com/iphonepng.zip. after the program is decompressed, copy the onepng binary file to the/Applications directory. Assume that your image is under the./img directory and you want to convert it to The./decode directory. Run the following command on the terminal:

 
 
  1. $ find ./img -name "*.png" -exec /Applications/iPhonePNG {} \; 

By default, after the converted image is added with a suffix, it is placed in the same directory of the original image and moved in batches:

 
 
  1. $ find ./img -name "*Decoded.png" -exec mv {} ./decode \; 

Summary:IPhoneThe introduction of the application development instance is complete. 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.