iOS學習之iOS 使用NINetworkImageView下載圖片,google地圖圖片的擷取。

來源:互聯網
上載者:User

 

一、NINetworkImageView是Nimbus下載圖片的類,類是這麼描述的:

 

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.

消耗很少的記憶體使用量網狀圖片.

 

使用線程以避免在UI線程上下載處理,並智能,調整最佳化記憶體的使用映像。

 

真的很好用,一步載入圖片。

 

首先#import "NimbusNetworkImage.h"標頭檔

在.m檔案添加:

 

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

 

 

另外一個種使用方法

 

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

 

 

Nimbus使用文檔:http://docs.nimbuskit.info/interface_n_i_network_image_view.html

 

 

二、NSString字串串連
NSString* string; // 結果字串

NSString* string1, string2; //已存在的字串

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

可以拼接很多,%@中間加逗號字串裡也帶逗號

 

三,NNString用法

 

----- 建立字串的方法-----//1、建立常量字串    NSString *astring = @"This is a String!";  //2、先建立一個空的字串,然後賦值;//    alloc和init組合則適合在函數之間傳遞參數,用完之後需要手工release    NSString *astring = [[NSString alloc] init];
    astring = @"This is a String!";
    NSLog(@"astring:%@",astring);
    [astring release];//3、在以上方法中,提升速度:initWithString方法    NSString *astring = [[NSString alloc] initWithString:@"This is a String!"];
    NSLog(@"astring:%@",astring);
    [astring release];
//4、建立臨時字串    NSString *astring;
    astring = [NSString stringWithCString:"This is a temporary string"];
    NSLog(@"astring:%@",astring);// OR    NSString *  scriptString = [NSString stringWithString:@" tell application \"Mail\"\r"];//5、建立格式化字串:預留位置(由一個%加一個字元組成)    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];

-----從檔案讀取字串-----
    NSString *path = @"astring.text";
    NSString *astring = [[NSString alloc] initWithContentsOfFile:path];
    NSLog(@"astring:%@",astring);
    [astring release];

-----寫字串到檔案----    
    NSString *astring = [[NSString alloc] initWithString:@"This is a String!"];
    NSLog(@"astring:%@",astring);
    NSString *path = @"astring.text";   
    [astring writeToFile: path atomically: YES];
    [astring release];   
-----比較兩個字串-----
//1、用C比較:strcmp函數
    char string1[] = "string!";
    char string2[] = "string!";
    if(strcmp(string1, string2) = = 0)
    {
        NSLog(@"1");
    }
 //2、isEqualToString方法   
    NSString *astring01 = @"This is a String!";
    NSString *astring02 = @"This is a String!";
    BOOL result = [astring01 isEqualToString:astring02];
    NSLog(@"result:%d",result);
//3、compare方法(comparer返回的三種值:NSOrderedSame,NSOrderedAscending,NSOrderedDescending)   
    NSString *astring01 = @"This is a String!";
    NSString *astring02 = @"This is a String!";   
    BOOL result = [astring01 compare:astring02] = = NSOrderedSame;   //NSOrderedSame 判斷兩者是否相同
    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 判斷兩對象值的大小(按字母順序進行比較,astring02大於astring01為真)

    NSString *astring01 = @"this is a String!";
    NSString *astring02 = @"This is a String!";
    BOOL result = [astring01 compare:astring02] = = NSOrderedDescending;   
    NSLog(@"result:%d",result);     
    //NSOrderedDescending 判斷兩對象值的大小(按字母順序進行比較,astring02小於astring01為真)
 //4、不考慮大小寫比較字串1
    NSString *astring01 = @"this is a String!";
    NSString *astring02 = @"This is a String!";
    BOOL result = [astring01 caseInsensitiveCompare:astring02] = = NSOrderedSame;   
    NSLog(@"result:%d",result);     
    //NSOrderedDescending判斷兩對象值的大小(按字母順序進行比較,astring02小於astring01為真)
//5、不考慮大小寫比較字串2
    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:不區分大小寫比較 NSLiteralSearch:進行完全比較,區分大小寫 NSNumericSearch:比較字串的字元個數,而不是字元值。

 四、列印日誌

    NSLog(@"%@ ",order);//列印字典

    NSLog(@"%@ ",imageUrlString);

 

五、google map 地圖取經緯度對應的圖片,並在中心插標

 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 顯示地圖圖片如下: center=後面是取圖片的經緯度,zoom是圖片放大縮小等級,size=  是需要的圖片大小,可根據需求調。color:後面是表徵圖的顏色,可以自己定義,比如換成red,  7C後面是插標的經緯度
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.