博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIImageView 一些属性设置
阅读量:4568 次
发布时间:2019-06-08

本文共 1816 字,大约阅读时间需要 6 分钟。

1.contentMode属性

这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,有以下几个常量可供设定:

UIViewContentModeScaleToFillUIViewContentModeScaleAspectFitUIViewContentModeScaleAspectFillUIViewContentModeRedrawUIViewContentModeCenterUIViewContentModeTopUIViewContentModeBottomUIViewContentModeLeftUIViewContentModeRightUIViewContentModeTopLeftUIViewContentModeTopRightUIViewContentModeBottomLeftUIViewContentModeBottomRight 注意以上几个常量,凡是没有带Scale的,当图片尺寸超过 ImageView尺寸时,只有部分显示在ImageView中。UIViewContentModeScaleToFill属性会导致图片变形。UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。

2.更改位置

更改一个UIImageView的位置,可以

2.1 直接修改其frame属性

2.2 修改其center属性:

imageView.center = CGPointMake(CGFloat x, CGFloat y);

 center属性指的就是这个ImageView的中间点。

2.3 使用transform属性

imageView.transform = CGAffineTransformMakeTranslation(CGFloat dx, CGFloat dy);

 其中dx与dy表示想要往x或者y方向移动多少,而不是移动到多少。

3、旋转图像

imageView.transform = CGAffineTransformMakeRotation(CGFloat angle);

  要注意它是按照顺时针方向旋转的,而且旋转中心是原始ImageView的中心,也就是center属性表示的位置。

  这个方法的参数angle的单位是弧度,而不是我们最常用的度数,所以可以写一个宏定义:

 #define degreesToRadians(x) (M_PI*(x)/180.0)

4、缩放图像

 还是使用transform属性:

imageView.transform = CGAffineTransformMakeScale(CGFloat scale_w, CGFloat scale_h);

5、为图片添加单击事件:

imageView.userInteractionEnabled = YES;UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];[imageView addGestureRecognizer:singleTap]; 一定要先将userInteractionEnabled置为YES,这样才能响应单击事件 6.其他设置
imageView.hidden = YES或者NO;    // 隐藏或者显示图片imageView.alpha = (CGFloat) al;    // 设置透明度imageView.highlightedImage = (UIImage *)hightlightedImage; 	// 设置高亮时显示的图片imageView.image = (UIImage *)image;	// 设置正常显示的图片[imageView sizeToFit];    // 将图片尺寸调整为与内容图片相同
 

转载于:https://www.cnblogs.com/LE-Quan/p/5130205.html

你可能感兴趣的文章
mysql 二进制日志
查看>>
阻止putty变成inactive
查看>>
TP框架代码学习 学习记录 3.2.3
查看>>
doc文档生成带目录的pdf文件方法
查看>>
js数组,在遍历中删除元素(用 for (var i in arr)是无效的 )
查看>>
通过前端上传图片等文件的方法
查看>>
在 OC 中调用 Swift 代码
查看>>
Android仿腾讯应用宝 应用市场,下载界面, 有了进展button
查看>>
安卓|五大逆向软件下载
查看>>
5 OK6410裸机调试(不用Jlink)
查看>>
“模板”学习笔记(5)-----编译器在处理函数模板的时候都干了啥
查看>>
教你用shell写CGI程序
查看>>
窗口 对话框 Pop Dialog 示例
查看>>
ubuntu(centos) server安装vmware tools
查看>>
数据结构之最大不重复串
查看>>
为什么要配置sdk-tools/platform-toools?
查看>>
自己动手开发更好用的markdown编辑器-07(扩展语法)
查看>>
maven dependency:tree中反斜杠的含义
查看>>
队列的循环队列
查看>>
程序中的日期格式
查看>>