zoukankan      html  css  js  c++  java
  • 使用UIImageView展现来自网络的图片

    本文转载至 http://www.cnblogs.com/chivas/archive/2012/05/21/2512324.html

    UIImageView:可以通过UIImage加载图片赋给UIImageView,加载后你可以指定显示的位置和大小。

    1、初始化

    UIImageView  *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0,45.0,300,300)];
    imageView.image = [UIImage imageNamed:@"a.png"];//加载入图片
    [self.view addSubView:image];
    [imageView release];
    //imageNamed方法是不能通过路径进行加载图片的,此方式容易引起发生内存警告从而导致自动退出的问题。

    //最好是通过直接读取文件路径[UIImage imageWithContentsOfFile]解决掉这个问题.

    NSImage *image = [[NSImage alloc]initWithContentsOfURL:(NSURL *)];
    NSImage *image = [[NSImage alloc]initWithContentsOfFile:(NSString *)];

    如:

    1、》》》

    UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
     
    2、》》》
    NSString *path = [[NSBundle mainBundle]pathForResource:@”icon”ofType:@”png”];
    NSImage *myImage = [UIImage imageWithContentsOfFile:path];

    //让一个UIImageView响应点击事件
      
    UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0,320, 44)];
    imgView.userInteractionEnabled=YES;
    UITapGestureRecognizer *singleTap =[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(onClickImage)];
    [imgView addGestureRecognizer:singleTap];
    [singleTap release];


     
    -(void)onClickImage{
       // here, do whatever you wantto do
        NSLog(@"imageview is clicked!");
    }

  • 相关阅读:
    Windows打开软件老是弹出无法验证发布者
    SpringMvc接受特殊符号参数被转义
    时代更替中的方正
    你应该知道的c# 反射详解
    C#使用System.Data.SQLite操作SQLite
    C# 动态调用WebService
    C# API: 生成和读取Excel文件
    11个强大的Visual Studio调试小技巧
    .Net 垃圾回收和大对象处理
    Visual Studio原生开发的10个调试技巧(一)
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/4190176.html
Copyright © 2011-2022 走看看