从零开始学习ios(UIImageView)控件及其属性

 //创建图片视图时就设定Frame的属性和大小

    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(60, 20, 80, 100)];

    [img setImage:[UIImage imageNamed:@"mtxx6"]];

    

  /* 创建图片视图的另外四种方法

   type img{

        UIImageView *img1 = [[UIImageView alloc]init];

        UIImageView *img2 = [[UIImageView ALLOC] initWithImage:(UIImage *)];

        UIImageView *img3 = [[UIImageView alloc] initWithImage:(UIImage *)];

        UIImageView *img4 = [[UIImageView alloc] initWithCoder:(NSCoder *)];

    }UIImageView

   */

     //设置Frame的属性,可以设置其位置和大小

  //img.frame = CGRectMake(CGFloat x, CGFloat y, <#CGFloat width#>, <#CGFloat height#>)

// bounds只能设置其大小,bounds是将UIImageView控件以原来的中心进行缩放。

//    img.bounds = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)

    //contentMode 设置图片的显示方式.我设置为根据视图进行等比列缩小

    img.contentMode = UIViewContentModeScaleAspectFit;

    //UIViewContentModeScaleAspectFill 保证部分图片比例不变,但是填充整个ImageView,可能只有部分图片显示出来了

    //UIViewContentModeScaleAspectFit 根据视图的比例而将Image全部显示与视图中,所以视图会部分空白

    //UIViewContentModeScaleToFill 图片根据图片视图窗口的大小然后进行填充,导致图片变形

    //UIViewContentModeRedraw  对缩放和尺寸调整过程中的视图外观控制

    //UIViewContentModeCenter  图片显示原图大小显示中间部分,

    //UIViewContentModeTop    图片显示原图大小显示上面部分

    //UIViewContentModeBottom 图片显示原图大小显示下面部分

    //UIViewContentModeLeft  图片显示原图大小显示左边部分

    //UIViewContentModeRight 图片显示原图大小显示右边部分

    //UIViewContentModeTopLeft 图片显示原图大小显示左上方部分

    //UIViewContentModeTopRight  图片显示原图大小显示右上方部分

    //UIViewContentModeBottomLeft 图片显示原图大小显示左下方部分

    //UIViewContentModeBottomRight 图片显示原图大小显示右下方部分

//    img.center = CGPointMake(40.0, 80.0);

    //center 更改UIImangeView的位置

//    img.transform = CGAffineTransformMakeRotation(60.0);

    //transfrom 围绕ImageView的中心顺时针旋转

//    img.transform = CGAffineTransformMakeScale(8.0,2.0);

    //transform 缩放图像

    //[img.layer setBorderColor:[[UIColor redColor] CGClolor]];

    [img.layer setBorderColor:[[UIColor redColor] CGColor] ];

   //bordercolor 设置边框颜色

    img.hidden = NO;//NO为显示图片,YES为隐藏图片

    img.alpha = 0.5;//设置透明度

    img.highlightedImage = [UIImage imageNamed:@"mtxx9"];

    // [img.layer setBorderColor: [[UIColor whiteColor] CGColor]];

    //setShouldRasterize 设置栅格化,NO不栅格化,YES会栅格层中的数据

    [img.layer setShouldRasterize:NO];

    /*

   

//设置圆角

    img.layer.cornerRadius=30.0;

    //是否隐藏边框之外的部分,默认为NO

    [img.layer setMasksToBounds:YES];

    //设置边框的宽度

    [img.layer setBorderWidth:5.0];

    //设置边框颜色

    [img.layer setBorderColor:[[UIColor blackColor] CGColor]];

    //为图片添加事件

    img.userInteractionEnabled = YES;

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];

[img addGestureRecognizer:singleTap];

//创建可变数组

NSMutableArray  *imgArray = [[NSMutableArray alloc] initWithCapacity:0];

    for (int i=15; i<21; i++) {

        UIImage *imgview = [UIImage imageNamed:[NSString stringWithFormat:@"mtxx%i",i]];

//将图片加载到可变数组里面

        [imgArray addObject:imgview];

    }

//将图片数组添加到视图中

     img.animationImages = imgArray;

    //设定所有的图片在多少秒播放完毕

    img.animationDuration = [imgArray count];

    //不重复播放多少遍,0表示无数遍

    img.animationRepeatCount = 0;

    //开始播放

    [img startAnimating];

    //将图片尺寸调整为内容图片相同

    [img sizeToFit];

 

    [self.view addSubview:img];

 

转载于:https://www.cnblogs.com/mybelief/p/4234761.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值