zoukankan      html  css  js  c++  java
  • UIImageView的简单使用

     1 - (void)viewDidLoad {
     2     [super viewDidLoad];
     3     //将图片转化为UIImage对象
     4     //png格式不需要加扩展名,其它格式图片需要
     5     UIImage* image1 = [UIImage imageNamed:@"a"];
     6     UIImage* image2 = [UIImage imageNamed:@"b"];
     7     
     8     UIImageView* imageV = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 70)];
     9     [self.view addSubview:imageV];
    10     //设置背景颜色
    11     imageV.backgroundColor = [UIColor orangeColor];
    12     //设置显示的图片
    13     imageV.image = image1;
    14     //改变图片填充方式
    15     //UIViewContentModeScaleAspectFit,等比例缩放,图片不变形
    16     //UIViewContentModeScaleAspectFill,等比例填充,填满
    17     imageV.contentMode = UIViewContentModeScaleAspectFit;
    18     //切除超出部分
    19 //    imageV.clipsToBounds = YES;
    20     
    21     //设置高亮图片
    22     imageV.highlightedImage = image2;
    23     imageV.highlighted = YES;
    24     
    25     
    26     //动画数组
    27     UIImageView* animateImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 190)];
    28     [self.view addSubview:animateImageView];
    29     //创建动画数组
    30     NSMutableArray* animateImages = [[NSMutableArray alloc] init];
    31     
    32     for (int i = 1; i < 22; i++) {
    33         //记得加扩展名(.jpg)
    34         NSString* imageName = [NSString stringWithFormat:@"%d.jpg",i];
    35         UIImage* image = [UIImage imageNamed:imageName];
    36         [animateImages addObject:image];
    37     }
    38     //设置需要播放的动画(图片数组)
    39     animateImageView.animationImages = animateImages;
    40     //设置动画时间
    41     animateImageView.animationDuration = 2;
    42     //设置重复次数(0是一直重复)
    43     animateImageView.animationRepeatCount = 0;
    44     
    45     //开始动画
    46     [animateImageView startAnimating];
    47     
    48     
    49 }
  • 相关阅读:
    WEB之CSS3系列笔记
    WEB之HTML5 系列笔记
    WEB之CSS系列笔记
    WEB 之 HTML 系列笔记
    npm安装(install)出现EPROTO: protocol error, symlink 解决方法
    笔记本电脑联网时没有WIFI列表选项可选
    Windows系统中下载Earthdata数据 2
    matlab cell
    【Linux系统】开启TFTP服务
    【Linux】搭建交叉编译环境
  • 原文地址:https://www.cnblogs.com/qiulilin/p/4592044.html
Copyright © 2011-2022 走看看