UI---UIImageView

来源:互联网 发布:淘宝女装批发店铺有吗 编辑:程序博客网 时间:2024/04/29 17:11

UIImageView是iOS中⽤用于显⽰示图⽚片的类,iOS中⼏几乎所有看到的图⽚片,都是由这个类来显⽰示的.

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImageView : UIView {  @private    id _storage;}

上代码

 UIImageView *imv = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];    imv.backgroundColor = [UIColor cyanColor];    //第一种获取图片方式//    imv.image = [UIImage imageNamed:@"1.jpg"];//如果是pnj格式的图片则可以省略格式名    //获取bundle里面图片的第二种形式    NSString *path = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"jpg"];//@"1.jpg"  nil    //也可以写成    NSString *path = [[NSBundle mainBundle]pathForResource:@"1.jpg" ofType:nil];    /*    但不可以写成    NSString *path = [[NSBundle mainBundle]pathForResource:nil ofType:@"1.jpg"];*/    imv.image = [UIImage imageWithContentsOfFile:path];

[NSBundle mainBundle]是指这里

添加动态图的方式

    UIImage *img1 = [UIImage imageNamed:@"1.tiff"];    UIImage *img2 = [UIImage imageNamed:@"2.tiff"];    UIImage *img3 = [UIImage imageNamed:@"3.tiff"];    UIImage *img4 = [UIImage imageNamed:@"4.tiff"];    UIImage *img5 = [UIImage imageNamed:@"5.tiff"];    UIImage *img6 = [UIImage imageNamed:@"6.tiff"];    imv.animationImages = @[img1,img2,img3,img4,img5,img6];    //动画循环的次数     imv.animationRepeatCount = 10;    //动画每次的时间    imv.animationDuration = 1;    //让动画开始的方法    [imv startAnimating];    //让动画停止    [imv stopAnimating];#####//imageView默认的userInteractionEnabled是NO,会阻断响应链    //意思是如果在图片上面加了例如button这样需要相应的东西,就一定要把imageView的userInteractionEnabled设置为YES;    imv.userInteractionEnabled = YES;
0 0
原创粉丝点击