UIImageView

//imageNamed 加载出来的图片,会一直占用程序的活跃内存,加载较大(占磁盘空间比较大)的图片,不宜使用此方法
    //UIImage *image = [UIImage imageNamed:@"map.png"];
    //mainBundle 主束,通过Bundle能够获取到资源在工程中的路径
    //pathForResource: 资源的名称
    //ofType:资源的后缀
    NSString *path = [[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
    //根据路径得到UIImage对象,不会一直占用程序的活跃内存(非常重要)
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    
    //默认情况下图片会按照UIImageView的大小来展示,如果图片过大,会被压缩,如果图片过小,会被拉伸
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,30,300,200)];
    //将图片赋值给imageView
    _imageView.image = image;
    [self.view addSubview:_imageView];
    
    NSMutableArray *imageArray = [NSMutableArray array];
    for (NSInteger i=1; i<=12; i++) {
        NSString *imageName = [NSString stringWithFormat:@"player%d.png",i];
        UIImage *image = [UIImage imageNamed:imageName];
        [imageArray addObject:image];
    }
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((320-64)/2,250,64,64)];
    //赋值一组图片(可以实现一组图片的自动轮播)
    imageView.animationImages = imageArray;
    //设置图片播放一轮的时长
    imageView.animationDuration = 5.0;
    //开始播放图片
    [imageView startAnimating];
    //[imageView stopAnimating];
    [self.view addSubview:imageView];
    
    
 //除了用allco initWithFrame的方式创建,还可以用图片直接初始化,如果用图片直接初始化,记得设frame
//UIImageView的高亮(highlighted)类似于UIButton的selected,是手动开关的。(图片的高亮用的不多)
//用图片初始化
- (id)initWithImage:(UIImage *)image;
//用图片和高亮图片初始化
- (id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage 
//图片属性
@property(nonatomic,retain) UIImage *image;
//高亮图片
@property(nonatomic,retain) UIImage *highlightedImage;
//高亮状态(默认是非高亮)
@property(nonatomic,getter=isHighlighted) BOOL highlighted;
//动画的图片数组
@property(nonatomic,copy) NSArray *animationImages;
//高亮状态下的动画图片数组
@property(nonatomic,copy) NSArray *highlightedAnimationImages;
//动画间隔
@property(nonatomic) NSTimeInterval animationDuration;
//动画循环次数,循环完以后会自动停止
@property(nonatomic) NSInteger animationRepeatCount; 
//开始动画
- (void)startAnimating;
//手动结束动画
- (void)stopAnimating;
//判断动画状态
- (BOOL)isAnimating;
//这个属性是UIView的,但是一般情况下只有UIImageView才会用到
@property(nonatomic) UIViewContentMode contentMode; 

 

posted @ 2015-04-07 20:09  孤独的根号下三  阅读(186)  评论(0编辑  收藏  举报