UIImageView的一些属性

来源:互联网 发布:pyqt4 windows 安装包 编辑:程序博客网 时间:2024/05/19 22:50

1.基本概念

 

 [self setExclusiveTouch:YES];//只能点一个

 

//设置window的背景 用图片进行配色

    //要保证图片的大小和 视图的frame一样大

    self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back2.jpg"]];

 

 

 //用户交互:默认是NO。UILabel和UIImageView是需要手动开启交互的。

    iv.userInteractionEnabled = YES;

    //裁剪

    iv.clipsToBounds = YES;

 

 

/*

     设置imageview的内容模式:

     1.默认是UIViewContentModeScaleToFill:拉伸或者压缩

     2.UIViewContentModeScaleAspectFit:根据imageview的较短的边发生等比例拉伸或压缩,以适应imageview的size

     3.UIViewContentModeScaleAspectFill:根据imageview的较长的边发生等比例拉伸或压缩(拉伸后可能会超出imageview的size,会发生裁剪)以适应imagview的size

     4.以下比较容易理解

     UIViewContentModeCenter,

     UIViewContentModeTop,

     UIViewContentModeBottom,

     UIViewContentModeLeft,

     UIViewContentModeRight,

     UIViewContentModeTopLeft,

     UIViewContentModeTopRight,

     UIViewContentModeBottomLeft,

     UIViewContentModeBottomRight,

     

    */

    [iv setContentMode:UIViewContentModeScaleAspectFit];

    

    //获取image的size

    //CGSize:结构体。

    CGSize imageSize = iv.image.size;

    NSLog(@"size = %@",NSStringFromCGSize(imageSize));

    //CGRect:结构体

    CGRect frame = iv.frame;

    NSLog(@"frame = %@",NSStringFromCGRect(frame));

    CGPoint pt = CGPointMake(34);

    NSLog(@"%@",NSStringFromCGPoint(pt));

2.Tom猫

 

-(void)createTomUIImageView

{

    UIImageView *tomImageView=[[UIImageView alloc]initWithFrame:[[UIScreen mainScreenbounds]];

   // tomImageView.image=[UIImage imageWithContentsOfFile:@"eat_03.jpg"];

    tomImageView.image=[UIImage imageNamed:@"eat_00.jpg"];

    [self.window addSubview:tomImageView];

    

    //数组中存放图片对象指针

    NSMutableArray *arr=[[NSMutableArray alloc]init];

    for (int i=0; i<40; i++) {

        NSString *Path=[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"eat_%.2d",i]ofType:@"jpg"];

       NSLog(@"%@",[NSString stringWithFormat:@"eat_%.2d",i]);

        UIImage * image=[UIImage imageWithContentsOfFile:Path];

        [arr addObject:image];

    }

      // NSLog(@"%@",arr);

    //1.在图片上添加一组图片

    [tomImageView setAnimationImages:arr];

    //2.设置动画的持续时间

    [tomImageView setAnimationDuration:5];

    //3.是否重复

    //如果想要无限重复下去,此处的只设置为-1

    [tomImageView setAnimationRepeatCount:-1];

    //4.开始动画效果

    [tomImageView startAnimating];

    

    //5.关闭动画

    //UIImageView不能与用户进行交互的

    //开启用户交互权限

    //userInteractionEnabled这个方法是用户权限的方法,多数空间都具有该方法,默认为NO

    tomImageView.userInteractionEnabled=YES;

    tomImageView.tag=100;

    //6.为图片是图添加手势

    

    //添加轻击手势

    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];

    //1.添加点击次数

    [tap setNumberOfTapsRequired:1];

    //2.添加手指的根数

    [tap setNumberOfTouchesRequired:1];

    //3.将手势添加到ImageView上

    [tomImageView addGestureRecognizer:tap];

    [tap release];

    [tomImageView release];

}

-(void)tapAction:(UITapGestureRecognizer *)tap

{

    static BOOL isStart=YES;

    if (isStart) {

        //通过手势查找添加手势的视图,必须要强制类型转换

        [(UIImageView *)tap.view stopAnimating];

        isStart=NO;

    }

    else

    {

        [(UIImageView *)tap.view startAnimating];

        isStart=YES;

    }

  

}




- (UIImage *)backgroundImage

{

    UIImage* img=Image(@"cellBackground");//原图

   UIEdgeInsets edge=UIEdgeInsetsMake(10,10,10,10);

    //UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片

    //UIImageResizingModeTile:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图

    img= [img resizableImageWithCapInsets:edgeresizingMode:UIImageResizingModeStretch];

   return img;

}


 
0 0
原创粉丝点击