UIImage

作者: 董立权 | 来源:发表于2017-12-14 13:19 被阅读0次
    + (nullable UIImage *)imageNamed:(NSString *)name;
    

    根据name生成图片
    系统有缓存,程序员无法回收

    + (nullable UIImage *)imageWithContentsOfFile:(NSString *)path;
    

    根据路径加载图片
    只要没有强引用,就会回收,传入全路径,不能加载Assets里面的图片

    + (nullable UIImage *)animatedImageWithImages:(NSArray<UIImage *> *)images duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);
    

    根据数组和持续时间生成动画图片
    images:动画图片数组
    duration:动画持续时间

    案例(动画图片)
    - (void)setupUI {
        //创建图片数组
        NSMutableArray *arrayM = [NSMutableArray array];
        
        for (int i = 1; i <= 25; i++) {
            //图片名称
            NSString *imageName = [NSString stringWithFormat:@"father%03d",i];
            //创建UIImage
            UIImage *image = [UIImage imageNamed:imageName];
            //添加到数组
            [arrayM addObject:image];
        }
        //参数1:要动画的图片数组
        //参数2:动画持续时间
        UIImage *img = [UIImage animatedImageWithImages:arrayM duration:2];
        
        //创建UIImageView
        UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 150)];
        //设置位置
        iv.center = self.view.center;
        //设置图片
        iv.image = img;
        //添加到父容器
        [self.view addSubview:iv];
        
    }
    

    相关文章

      网友评论

          本文标题:UIImage

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