zoukankan      html  css  js  c++  java
  • UIImageView控件使用(转)

    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 allocinitWithFrame:CGRectMake(00,32044)];
    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 任务调度程序定时执行Python脚本
    sklearn 学习 第三篇:knn分类
    sklearn 学习 第二篇:特征预处理
    sklearn 学习 第一篇:分类
    DAX 第六篇:统计函数(描述性统计)
    DAX 第四篇:CALCULATE详解
    DAX 第三篇:过滤器函数
    DAX 第二篇:计算上下文
    DAX 第一篇:数据模型
    Git 第二篇:基本操作
  • 原文地址:https://www.cnblogs.com/king1596/p/2739257.html
Copyright © 2011-2022 走看看