//
// ViewController.m
// 03-UIImageView的使用
// #import "ViewController.h" @interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *image2; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 1.创建UIImageView对象
UIImageView *imageView = [[UIImageView alloc] init]; // 2. 设置尺寸
// imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//imageView.frame = self.view.bounds;//同上 imageView.frame = CGRectMake(, , , );
NSLog(@"%f",self.view.bounds.origin.x);
NSLog(@"%f",self.view.bounds.origin.y);
NSLog(@"%f",self.view.bounds.size.height);
NSLog(@"%f",self.view.bounds.size.width); // 3. 设置背景颜色
imageView.backgroundColor = [UIColor redColor]; // 4. 设置背景图片
imageView.image = [UIImage imageNamed:@""];//1图片,png, _image2.image = [UIImage imageNamed:@""];
_image2.frame = CGRectMake(, , , );
_image2.contentMode = UIViewContentModeCenter;
_image2.backgroundColor = [UIColor redColor];
//[self.view addSubview:_image2]; // 5.设置图片的内容模式
imageView.contentMode = UIViewContentModeScaleAspectFill; // 6.加毛玻璃,图片上加一个UIToolBar // 6.1 创建UIToolBar对象
UIToolbar *toolBar = [[UIToolbar alloc] init];
// 6.2 设置toolBar的frame
toolBar.frame = imageView.bounds;
// 6.3 设置毛玻璃的样式
toolBar.barStyle = UIBarStyleBlack;
toolBar.alpha = 0.98;
// 6.4 加到imageView中
[imageView addSubview:toolBar]; // 加到控制器的view中
[self.view addSubview:imageView]; } - (void)test{
// 1.1 创建UIImageView对象
UIImageView *imageView = [[UIImageView alloc] init]; // 1.2 设置frame
imageView.frame = CGRectMake(, , , ); // 1.3 设置背景
// imageView.backgroundColor = [UIColor greenColor]; // 1.4 设置图片 (png不需要后缀)
imageView.image = [UIImage imageNamed:@""]; /** UIViewContentModeRedraw, // 重新绘制 (核心绘图) drawRact //带有Scale,标明图片有可能被拉伸或压缩
UIViewContentModeScaleToFill, // 完全的压缩或拉伸 // Aspect 比例,缩放是带有比例的
UIViewContentModeScaleAspectFit, // 宽高比不变 Fit 适应
UIViewContentModeScaleAspectFill, // 宽高比不变 Fill 填充 //不带有Scale,标明图片不可能被拉伸或压缩
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
*/
// 1.5 设置图片的内容模式
imageView.contentMode = UIViewContentModeScaleAspectFill; // 2.0 加到控制器的view中
[self.view addSubview:imageView]; // 裁剪多余的部分
imageView.clipsToBounds = YES;
} @end
//
// ViewController.m
// 04-UIImageView的frame设置
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
/* // 设置frame的方式
// 方式一
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:@"1"]; // imageView.frame = CGRectMake(100, 100, 267, 400);
// imageView.frame = (CGRect){{100, 100},{267, 400}}; //位置尺寸
*/ // 方式二
/*
UIImageView *imageView = [[UIImageView alloc] init];
// 创建一个UIImage对象
UIImage *image = [UIImage imageNamed:@"1"];
// 设置frame
imageView.frame = CGRectMake(100, 10, image.size.width, image.size.height);
// 设置图片
imageView.image = image;
*/ // 方式三
/*
// 创建一个UIImage对象
UIImage *image = [UIImage imageNamed:@"1"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 10, image.size.width, image.size.height)];
imageView.image = image;
*/ // 方式四 // 创建一个UIimageview对象
// 注意: initWithImage 默认就有尺寸--->图片的尺寸
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]]; // 改变位置
// imageView.center = CGPointMake(200, 150); imageView.center = CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.5); [self.view addSubview:imageView];
} @end

ios7--UIImageView的更多相关文章

  1. iOS7上TableViewCell的button和UIImageView个别未显示的bug

    要做这个cell,用xib将cell做成之后,在iPhone6.6Plus.5s上运行良好,但是在iOS7的5s和iPad上,黄色的小星星和下载按钮均没有显示. 甚为惊奇. 在网上百度之,发现了解决办 ...

  2. 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

  3. iOS 读取相册二维码,兼容ios7(使用CIDetector 和 ZXingObjC)

    ios从相册读取二维码,在ios8以上,苹果提供了自带的识别图片二维码的功能,这种方式效率最好,也是最推荐的,但是如果你的系统需要向下兼容ios7,就必须用其他方式. 这里我选择的是 ZXingObj ...

  4. iOS7初体验(3)——图像资源Images Assets

    开始之前,首先回顾一下iOS7初体验(1)——第一个应用程序HelloWorld中的一张图,如下所示: 本文便分享一下Images.xcassets的体验~_~ 1. 打开此前使用过的HelloWor ...

  5. ios NSURLSession(iOS7后,取代NSURLConnection)使用说明及后台工作流程分析

    NSURLSession是iOS7中新的网络接口,它与咱们熟悉的NSURLConnection是并列的.在程序在前台时,NSURLSession与NSURLConnection可以互为替代工作.注意, ...

  6. iOS7中如何去除UINavigationbar下边的那条黑线

    做项目过程中遇到要去掉导航栏下面的一条黑线,从网上找到的一个方法 默认UINavigationbar样式 准备用于替换的背景 替换后的效果 if ([self.navigationController ...

  7. 【转】自定义iOS7导航栏背景,标题和返回按钮文字颜色 -- 不错不错!!

    原文网址:http://blog.csdn.net/mad1989/article/details/41516743 在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更 ...

  8. 【转】 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    原文:http://blog.csdn.net/mad1989/article/details/41516743 UIBarButtonItem,navigationItem,backBarButto ...

  9. iOS7——图像资源Images Assets

    iOS7初体验(3)——图像资源Images Assets 分类: iOS开发2013-06-18 16:02 17583人阅读 评论(2) 收藏 举报 ios7Images xcassets图像资源 ...

  10. ##DAY2 UILabel、UITextField、UIButton、UIImageView、UISlider

    ##DAY2 UILabel.UITextField.UIButton.UIImageView.UISlider #pragma mark ———————UILabel——————————— UILa ...

随机推荐

  1. DWG转PDF

    DWG转PDF DWG转换PDF有两种方法,一种是利用PDF打印机,一种是利用专业软件: 利用PDF打印机最直接,但是不能批量打印,下面讲一下利用专业软件如何进行批量转换,在这里以梦想CAD软件(Mx ...

  2. 04C语言输入输出

    C语言输入输出 输入字符getchar() #include <stdio.h> int main(){ putchar(getchar()); putchar(getchar()); ; ...

  3. 暴力搜索+散列--P1008 三连击

    题目描述 将1,2, ⋯,9共9个数分成3组,分别组成3个三位数,且使这3个三位数构成1:2:3的比例,试求出所有满足条件的3个三位数. 输入输出格式 输入格式: 木有输入 输出格式: 若干行,每行3 ...

  4. (C/C++学习)20.基于C++改进的单目标遗传算法

    说明:在学习生活中,经常会遇到各种各样的最优问题,其中最常见的就是求某个多维(多个自变量)函数在各个自变量各取何值时的最大值或最小值:例如求函数 f(x) = (x-5)2+(y-6)2+(z-7)2 ...

  5. 深入分析同步工具类之AbstractQueuedSynchronizer

      概览: AQS(简称)依赖内部维护的一个FIFO(先进先出)队列,可以很好的实现阻塞.同步:volatile修饰的属性state,哪个线程先改变这个状态值,那么这个线程就获得了优先权,可以做任何事 ...

  6. buf.readInt8()

    buf.readInt8(offset[, noAssert]) offset {Number} 0 noAssert {Boolean} 默认:false 返回:{Number} 从该 Buffer ...

  7. Django-F和Q函数作用与使用

    F函数 能够解析对现有查询对象的引用的对象. obj = Score.objects.get(stuid=') obj.score += 1 obj.order.save() 执行出的SQL语句 wh ...

  8. sql杂记:一些坑和数据库恢复

    这是一篇纯粹的乱七八糟的笔记...(勿喷)主要记录一下初入SQL坑的杂七杂八的注意事项. 一.先补充下事务的写法: start transaction;#开始事务 --各种事务... commit;# ...

  9. PAT 1134 Vertex Cover

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

  10. cocos2dx 用命令行进行编译的指令

    cocos compile -p android -m release -s F:\cocosproj\antest --ap android-20 上面那条就是我常用的指令,这指令修改一下就成了你的 ...