美文网首页
UIImageView控件:1-基本使用

UIImageView控件:1-基本使用

作者: 赵亦晨 | 来源:发表于2016-11-08 16:42 被阅读0次

    UIImageView是用来显示图片的UI控件,本文重点介绍该控件在实际的App开发中常见的一些操作,如:初始化、设置圆角与边框、以及设置填充模式contentMode。

    1、UIImageView与UIImage的区别

    UIImageView:是UI控件,继承自UIView,是用来显示图片的空间,UIImageView中有一个UIImage类型的属性:image,用来存放需要显示的图片;

    UIImage:可以理解为是图片文件,文件是不能显示的,文件相当于保存在磁盘上的一堆二进制代码。UIImage的父类是NSObject。UIImage对象的初始化方法,根据image所处的位置不同而不同。

    +(nullableUIImage*)imageNamed:(NSString*)name;// 从Assets文件夹中加载图片

    +(nullableUIImage*)imageWithContentsOfFile:(NSString*)path;//从Supporting File文件夹中加载图片

    2、设置圆角/圆形头像

    //设置圆角

    self.imageView.layer.cornerRadius=5;

    self.imageView.layer.masksToBounds=YES;

    3、设置边框

    self.imageView.layer.borderWidth=5;

    self.imageView.layer.borderColor=[UIColorwhiteColor].CGColor;

    4、添加手势点击事件

    UITapGestureRecognizer*tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap:)];

    [self.imageView addGestureRecognizer:tap];

    self.imageView.userInteractionEnabled=YES;

    相关文章

      网友评论

          本文标题:UIImageView控件:1-基本使用

          本文链接:https://www.haomeiwen.com/subject/ukoauttx.html