zoukankan      html  css  js  c++  java
  • (iphone开发)从网络读取图片并显示

    NSString *urlString = @"http://img4.bitauto.com/autoalbum/files/20100226/003/201002260944098032_1155951_4.jpg";
    NSURL *url = [NSURL URLWithString:urlString];
    NSData *myData = [NSData dataWithContentsOfURL: url];
    UIImage *myImage = [UIImage imageWithData: myData];
    UIImageView *myImageView = [[UIImageView alloc] initWithImage: myImage];
    UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
    myScrollView.contentSize = CGSizeMake(myImage.size.width, myImage.size.height;
    [self.view addSubview: myScrollView];
    [myScrollView release];
    [myScrollView addSubview: myImageView];
    [myImageView release];
    如果返回url是nil,则用下面的代码代替:
    NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  • 相关阅读:
    socket
    netstat
    列表
    突然发现不会写代码了
    算法资源
    bit位操作
    排序算法
    连续子数组最大和
    books
    凸优化
  • 原文地址:https://www.cnblogs.com/top5/p/2414336.html
Copyright © 2011-2022 走看看