动态图片加到UIImageView中

//1.添加一个.gif类型的动态的图片,用到URLForResource方法,gif是图片的格式,FlagZombie是图片的名字

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
   
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"FlagZombie" withExtension:@"gif"];
    UIImage *img = [UIImage animatedImageWithAnimatedGIFURL:url];
    //创建一个UIImageView类型的对象
    UIImageView *iv = [[UIImageView alloc]init];
    iv.image = img;//把这个对象的image属性设置为img
    iv.frame = CGRectMake(50, 50, 200, 150);
    [self.view addSubview:iv];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

//需要完成功能还需要在文件中添加第三方库,库在我的文件中有。

posted @ 2015-09-16 23:03  阿凡提王  阅读(122)  评论(0编辑  收藏  举报