UI day 6 UIImageView UIImage图片类 UISitch开关控件 UIStepper加减控件 U UISegmentedControl 分段控制器


                          UIImageView和UIImage

1.UIImageView是用来显示图片的控件,相当于相框,用来显示UIImage对象

2.初始化UIImage对象,及为其加载图片
有两种方式:
方式一
UIImage *image = [ UIImage imageNamed : @"1.JPG" ];

方式二:
通过图片的路径加载图片,通过应用程序包找出图片 NSBundle(应用程序包类);
[NSBundle mainBundle] 获取当前应用程序包对象
  pathForResource: 资源名称   ofType: 资源类型

NSString   *filePath = [[ NSBundle mainBundle ] pathForResource : @"2" ofType : @"JPG" ];
UIImage *image2 = [ UIImage imageWithContentsOfFile :filePath];

3.总结: 第一种方式:如果这个图片资源被多次使用,使用第一种方式,此种方式会把图片对象添加到应用程序的缓存中,多次使用时比较方便,缺点:占用内存
    
     第二种方式:如果这个图片资源只被使用一次,使用第二种方式,此种方式不会吧图片对象添加到应用程序缓存中,缺点:比较耗时

4. 创建 UIImage 对象
   
    UIImageView   *imageView = [[UIImageView alloc]initWithImage:image];
    配置属性
    设置 frame
    imageView. frame = [ UIScreen   mainScreen ]. bounds ;
    重新设置图片
    imageView.image = image2;
    添加到父视图
    [ self . view addSubview :imageView];
    [imageView release ];

5.   //UIImageview 加载动态图片
    //1. 准备一组图片,使用数组存放
    NSMutableArray *imageArray = [ NSMutableArray arrayWithCapacity : 7 ];
   
   
    //2. 使用 for 循环添加图片
    for ( int i = 1 ; i < 8 ; i++) {
        // 确定图片的名字
        NSString *name =[ NSString stringWithFormat : @"huoju_%d.tiff" ,i];
        // 初始化 image 对象
        UIImage *image = [ UIImage imageNamed :name];
        // 将图片添加到数组中
        [imageArray addObject :image];
    }
   
    NSLog ( @"%@" ,imageArray);
   
    UIImageView *fireImageView =[[ UIImageView alloc ] initWithFrame : CGRectMake ( 120 , 100 , 79 , 106 )];
    fireImageView. backgroundColor = [ UIColor   redColor ];
    fireImageView. layer . cornerRadius = 30 ;
    // 设置 UIimageview 播放动态图片需要的数组
    fireImageView. animationImages = imageArray;
    // 设置播放动态图片的时间间隔
    fireImageView. animationDuration = 0.1 ;
    // 设置重复次数
    fireImageView. animationRepeatCount = 100 ;
   
    // 启动动态图片 , 对动画的配置写在动画开始之前 VIP
    [fireImageView startAnimating ];
   
    // 添加到父视图
    [ self . view   addSubview :fireImageView];
    [fireImageView release ];

6. // 等比缩放图片
    // 取出 8.JPG
    NSString   *filePath2 = [[ NSBundle mainBundle ] pathForResource</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值