IOS learning iOS uses NINetworkImageView to download images and retrieve images from google Maps.

Source: Internet
Author: User

 

1. NINetworkImageView is the class for downloading images by Nimbus. The class is described as follows:

 

Overview

A network-enabled image view that consumes minimal amounts of memory.

Intelligently crops and resizes images for optimal memory use and uses threads to avoid processing images on the UI thread.

Network images consume a small amount of memory.

 

Use threads to avoid downloading and processing on the UI thread and intelligently adjust and optimize the memory usage images.

 

It's really easy to use. load images in one step.

 

First # import "NimbusNetworkImage. h" header file

Add the following in the. m file:

 

     UIImage* image = [UIImage imageWithContentsOfFile:                      NIPathForBundleResource(nil, @"abcd@2x.png")];    NINetworkImageView* imageView = [[NINetworkImageView alloc] initWithImage:image];        // Method #1: Use the image's frame to determine the display size for the network image.    imageView.frame = CGRectMake(0, 0, 58, 58);    NSString* start_latitude = start_latitude;    NSString* start_longitude = start_longitude];        NSString* imageUrlString = @"http://maps.googleapis.com/maps/api/staticmap?center=";    NSString* imageUrlStringEnd = @"&zoom=14&size=600x800&maptype=roadmap&markers=color:red%7C";    imageUrlString = [imageUrlString stringByAppendingFormat:@"%@%@%@%@%@%@%@%@",start_latitude,@",",start_longitude,imageUrlStringEnd,start_latitude,@",",start_longitude,@"&sensor=false"];

 

 

Another method

 

/ Method #2: use the method setPathToNetworkImage:forDisplaySize:  [imageView setPathToNetworkImage: @"http://farm2.static.flickr.com/1165/644335254_4b8a712be5.jpg"                    forDisplaySize: CGSizeMake(100, 100)];

 

 

Nimbus User Manual: http://docs.nimbuskit.info/interface_n_ I _network_image_view.html

 

 

Ii. NSString connection
NSString * string; // result string

NSString * string1, string2; // an existing string

1. string = [NSString initWithFormat: @ "% @, % @", string1, string2];
2. string = [string1 stringByAppendingString: string2]; </p>
3. string = [string stringByAppendingFormat: @ "% @, % @", string1, string2];

 

4. string = [string stringByAppendingFormat: @ "% @", string1, string2, string3, string4......];

You can splice a lot of data, and the % @ string must contain commas (,).

 

Iii. NNString usage

 

----- Create a string----- // 1. Create a constant String NSString * astring = @ "This is a String! "; // 2. Create an empty string and assign a value first. // The combination of alloc and init is suitable for passing parameters between functions, after use, manually release NSString * astring = [[NSString alloc] init];
Astring = @ "This is a String! ";
NSLog (@ "astring: % @", astring );
[Astring release]; // 3. In the above method, the speed is improved: initWithString method NSString * astring = [[NSString alloc] initWithString: @ "This is a String! "];
NSLog (@ "astring: % @", astring );
[Astring release];
// 4. Create a temporary string NSString * astring;
Astring = [NSString stringWithCString: "This is a temporary string"];
NSLog (@ "astring: % @", astring); // OR NSString * scriptString = [NSString stringWithString: @ "tell application \" Mail \ "\ r"]; // 5. Create a formatted string: A placeholder (consisting of one % and one character) int I = 1;
Int j = 2;
NSString * astring = [[NSString alloc] initWithString: [NSString stringWithFormat: @ "% d. This is % I string! ", I, j];
NSLog (@ "astring: % @", astring );
[Astring release];

-----Read strings from a file-----
NSString * path = @ "astring. text ";
NSString * astring = [[NSString alloc] initWithContentsOfFile: path];
NSLog (@ "astring: % @", astring );
[Astring release];

-----Write a string to a file----
NSString * astring = [[NSString alloc] initWithString: @ "This is a String! "];
NSLog (@ "astring: % @", astring );
NSString * path = @ "astring. text ";
[Astring writeToFile: path atomically: YES];
[Astring release];
-----Compare two strings-----
// 1. Comparison with C: strcmp Function
Char string1 [] = "string! ";
Char string2 [] = "string! ";
If (strcmp (string1, string2) = 0)
{
NSLog (@ "1 ");
}
// 2. isdomaintostring Method
NSString * astring01 = @ "This is a String! ";
NSString * astring02 = @ "This is a String! ";
BOOL result = [astring01 isw.tostring: astring02];
NSLog (@ "result: % d", result );
// 3. compare (three values returned by comparer: NSOrderedSame, NSOrderedAscending, NSOrderedDescending)
NSString * astring01 = @ "This is a String! ";
NSString * astring02 = @ "This is a String! ";
BOOL result = [astring01 compare: astring02] = NSOrderedSame; // determine whether the two are the same
NSLog (@ "result: % d", result );

NSString * astring01 = @ "This is a String! ";
NSString * astring02 = @ "this is a String! ";
BOOL result = [astring01 compare: astring02] = NSOrderedAscending;
NSLog (@ "result: % d", result );
// NSOrderedAscending determines the size of the two objects (which is compared alphabetically. astring02 is true if it is greater than astring01)

NSString * astring01 = @ "this is a String! ";
NSString * astring02 = @ "This is a String! ";
BOOL result = [astring01 compare: astring02] = NSOrderedDescending;
NSLog (@ "result: % d", result );
// NSOrderedDescending determines the size of the two object values (which are compared alphabetically. astring02 is true if it is smaller than astring01)
// 4. Compare string 1 without case sensitivity
NSString * astring01 = @ "this is a String! ";
NSString * astring02 = @ "This is a String! ";
BOOL result = [astring01 caseInsensitiveCompare: astring02] = NSOrderedSame;
NSLog (@ "result: % d", result );
// NSOrderedDescending determines the size of the two object values (which are compared alphabetically. astring02 is true if it is smaller than astring01)
// 5. Compare string 2 with case insensitive
NSString * astring01 = @ "this is a String! ";
NSString * astring02 = @ "This is a String! ";
BOOL result = [astring01 compare: astring02
Options: NSCaseInsensitiveSearch | NSNumericSearch] = NSOrderedSame;
NSLog (@ "result: % d", result );
// NSCaseInsensitiveSearch: case-insensitive comparison NSLiteralSearch: performs a full comparison. case-sensitive NSNumericSearch: compares the number of characters of a string, not the character value.

4. Print logs

NSLog (@ "% @", order); // print the dictionary

NSLog (@ "% @", imageUrlString );

 

5. google map takes the image corresponding to the longitude and latitude, and marks it in the center

Http://maps.googleapis.com/maps/api/staticmap? Center = 40.08029, 116.58797 & zoom = 14 & size = 600x500 & maptype = roadmap & markers = color: blue % 7C40. 08029,116.58797 & sensor = false: the map image is displayed as follows: center = the image's latitude and longitude are followed by zoom. zoom is the image zoom level. size = is the required image size, which can be adjusted as needed. Color: The color behind the icon. You can define it by yourself. For example, if you change it to red, the longitude and latitude of the plug-in will be followed by 7C.
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.