UI_UIImageView 基本操作,ui_uiimageview
UI_UIImageView 常用方法
// 使用ImageView 通過 name 找到圖片 UIImage *image = [UIImage imageNamed:@"bg_2"]; // 添加 image 到 imageView 上 UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; // 設定圖片位置和大小 imageView.frame = CGRectMake(40, 40, 90, 160); imageView.backgroundColor = [UIColor redColor]; // 設定透明度 imageView.alpha = 0.5; // 為圖片添加點擊事件 // userInteractionEnabled 為 YES ,才能響應點擊事件 imageView.userInteractionEnabled = YES; // 設定圖片可以互動 // 設定手勢 UITapGestureRecognizer *singleTag = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)]; // 添加手勢 [imageView addGestureRecognizer:singleTag]; // 顯示/隱藏 YES 為隱藏 imageView.hidden = NO; // 擷取網路中的圖片 UIImage *netImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.google.com"]]]; // 將 image 添加到 window 上,並釋放記憶體 [self.window addSubview:imageView]; [imageView release]; imageView = nil; // 安全釋放
動態圖
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.tiff"]]; imageView.frame = CGRectMake(40, 50, 100, 100); // 把一組圖片加到 imageView 上面 NSMutableArray *array = [NSMutableArray array]; for (int i = 1; i < 5; i++) {// NSString *name = [NSString stringWithFormat:@"00%d.tiff", i];// UIImage *image = [UIImage imageNamed:name]; // 上面兩句可以合為一句 UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff", i]]; [array addObject:image]; } // 把數組放到imageView中 imageView.animationImages = array; [self addSubview:imageView]; // 播放時間 imageView.animationDuration = 0.4f; // 播放次數 imageView.animationRepeatCount = 0; // 0 就是無限次 // 開始動畫 [imageView startAnimating]; // 結束動畫】// [imageView stopAnimating];
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。