IOS基礎控制元件UIImageView
阿新 • • 發佈:2018-12-15
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; //UIImageView是管理圖片的類 UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)]; imageV.backgroundColor = [UIColor yellowColor]; [self.view addSubview: imageV]; //建立一個圖片 UIImage *ima = [UIImage imageNamed:@"1.jpeg"]; //顯示圖片 imageV.image = ima; //播放逐幀動畫 NSMutableArray *array = [NSMutableArray array]; for(int i=1;i<=30;i++){ //圖片的名字需要為1.png - 30.png NSString *name = [NSString stringWithFormat:@"%d",i]; UIImage *image = [UIImage imageNamed:name]; [array addObject:image]; } //將圖片陣列放入UIImageView中 imageV.animationImages=array; //設定逐幀動畫的總時間,單位是秒 imageV.animationDuration = 0.2; //這裡是設定重複次數 imageV.animationRepeatCount = 20; //開啟動畫 [imageV startAnimating]; //停止動畫 // [imageV stopAnimating]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end