UI_UIImageView 基本操作
2016-01-26 18:29
477 查看
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];
相关文章推荐
- zoj 3911 Prime Query 第一发线段树
- LeetCode Question Difficulty Distribution
- 【转】android UI进阶之自定义组合控件
- JS ueditor编辑器
- phpQuery采集乱码问题解决方案
- 二:UIKit与Quartz 2D绘图技术学习
- 整合UEditor,SSH下
- not-null property references a null or transient value:
- X-Requested-With
- 下拉刷新时UITableView的section headerView冲突的解决
- 设备管理,连接两个数据库,用的easygui
- 如何创建UIlabel,使label的高度随着内容的多少而变动并且可以设置行间距?
- NSString, char, NSData,UIImage相互转化
- virt-install Guest name 'test' is already in use解决办法
- iOS 瀑布流的简单实现 UICollectionView
- Android Bluetooth笔记
- leetcode 63. Unique Paths II
- Lucene BooleanQuery实现
- It is indirectly referenced from required .class files
- 函数参数之 传常引用(passed by reference to const)替换 传值(passed by value)