码迷,mamicode.com
首页 > 其他好文 > 详细

UIimage与UIimageView

时间:2016-02-26 12:14:41      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

UIimage是用来作为存储一张图片的容器,而UIimageView则是用来接收UIimage的一个模块,单独的UIimage是无法显示在屏幕上的,下面记录了一些常用的方法。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //UIimage png jpg bmp(颜色有问题) gif(不支持)
    NSString *path = [[NSBundle mainBundle]resourcePath];
    //NSString *imagePath = [NSString stringWithFormat:@"%@/1.jpeg",path];
    //UIImage *image = [[UIImage alloc]initWithContentsOfFile:imagePath];
#if 0
    UIImage *image = [UIImage imageNamed:@"1.jpeg"];
    
    //载体:一定要有载体才可以把图片显示在屏幕上
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    //图片显示在屏幕上的大小是由载体控制的
    imageView.frame = CGRectMake(10, 100, 355, 400);
    imageView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:imageView];
    
    //内容模式
    /*UIViewContentModeScaleToFill - 拉伸充满整个载体
     UIViewContentModeScaleAspectFill - 拉伸不改变比例,充满最大的一边
     UIViewContentModeScaleAspectFit - 拉伸不改变比例,充满最小的一边
     */
    imageView.contentMode = UIViewContentModeScaleAspectFit;
#endif
    //UIImageView动画 - 播放序列图
    NSMutableArray *imageArray = [[NSMutableArray alloc]init];
    for (int i=0;i<=3;i++)
    {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i]];
        [imageArray addObject:image];
    }
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.frame = CGRectMake(102, 100, 102, 66);
    [self.view addSubview:imageView];
    //设置动画数组
    imageView.animationImages = imageArray;
    //设置播放周期时间(秒)
    imageView.animationDuration = 0.2;
    //执行次数(给0动画不限制次数)
    imageView.animationRepeatCount = 2;
    //开始播放动画
    [imageView startAnimating];
    
}

 

UIimage与UIimageView

标签:

原文地址:http://www.cnblogs.com/superorangecc/p/5219725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!