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:
- NSString * bodyStr = @ "google + ";
- [UrlRequestsetHTTPBody: [bodyStr dataUsingEncoding: NSUTF8StringEncoding];
- // 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:
- NSString*bodyStr =@"google+";
- NSString*bStr =CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
- (CFStringRef)bodyStr,
- NULL,
- CFSTR(":/?#[]@!$&’()*+,;="),
- kCFStringEncodingUTF8);
- [urlRequest setHTTPBody:[bStr dataUsingEncoding:NSUTF8StringEncoding]];
- [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:
- 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:
- UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 200, 20)];
- titleText.backgroundColor = [UIColor clearColor];
- [titleText setFont:[UIFont systemFontOfSize:15.0]];
- [titleText setText:@"Elimination phase Day 1"];
- self.navigationItem.titleView=titleText;
- [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:
- $ 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:
- $ 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!