美文网首页
GCD线程通信11

GCD线程通信11

作者: Sunney | 来源:发表于2016-06-02 09:58 被阅读12次

    在storyborad中拖拽UIImageView

    //关联属性

    @property (weak,nonatomic) IBOutlet UIImageView *imageView;

    - (void)touchesBegan:(NSSet *)touches withEvent :(UIEvent *)event{

    //图片的网络途径

    NSURL *url = [NSURL URLWithString:@"http://img.pconline.com.cn/images/photoblog/9/9/8/1/9981681/200910/11/1255259355826.jpg"]

    //加载图片

    NSData *data = [NSData dataWithContentsOfURL:url];

    //生成图片

    UIImage *image = [UIImage imageWithData:data];

    //回到主线程

    dispatch_async(dispatch_get_main_queue(),^{

    self.imageView.image = image;

    });

    }

    相关文章

      网友评论

          本文标题:GCD线程通信11

          本文链接:https://www.haomeiwen.com/subject/gmxkdttx.html