ios7--UIImageView
//
// 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的更多相关文章
- iOS7上TableViewCell的button和UIImageView个别未显示的bug
要做这个cell,用xib将cell做成之后,在iPhone6.6Plus.5s上运行良好,但是在iOS7的5s和iPad上,黄色的小星星和下载按钮均没有显示. 甚为惊奇. 在网上百度之,发现了解决办 ...
- 自定义iOS7导航栏背景,标题和返回按钮文字颜色
在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...
- iOS 读取相册二维码,兼容ios7(使用CIDetector 和 ZXingObjC)
ios从相册读取二维码,在ios8以上,苹果提供了自带的识别图片二维码的功能,这种方式效率最好,也是最推荐的,但是如果你的系统需要向下兼容ios7,就必须用其他方式. 这里我选择的是 ZXingObj ...
- iOS7初体验(3)——图像资源Images Assets
开始之前,首先回顾一下iOS7初体验(1)——第一个应用程序HelloWorld中的一张图,如下所示: 本文便分享一下Images.xcassets的体验~_~ 1. 打开此前使用过的HelloWor ...
- ios NSURLSession(iOS7后,取代NSURLConnection)使用说明及后台工作流程分析
NSURLSession是iOS7中新的网络接口,它与咱们熟悉的NSURLConnection是并列的.在程序在前台时,NSURLSession与NSURLConnection可以互为替代工作.注意, ...
- iOS7中如何去除UINavigationbar下边的那条黑线
做项目过程中遇到要去掉导航栏下面的一条黑线,从网上找到的一个方法 默认UINavigationbar样式 准备用于替换的背景 替换后的效果 if ([self.navigationController ...
- 【转】自定义iOS7导航栏背景,标题和返回按钮文字颜色 -- 不错不错!!
原文网址:http://blog.csdn.net/mad1989/article/details/41516743 在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更 ...
- 【转】 自定义iOS7导航栏背景,标题和返回按钮文字颜色
原文:http://blog.csdn.net/mad1989/article/details/41516743 UIBarButtonItem,navigationItem,backBarButto ...
- iOS7——图像资源Images Assets
iOS7初体验(3)——图像资源Images Assets 分类: iOS开发2013-06-18 16:02 17583人阅读 评论(2) 收藏 举报 ios7Images xcassets图像资源 ...
- ##DAY2 UILabel、UITextField、UIButton、UIImageView、UISlider
##DAY2 UILabel.UITextField.UIButton.UIImageView.UISlider #pragma mark ———————UILabel——————————— UILa ...
随机推荐
- js延时加载的方法
js的延迟加载有助与提高页面的加载速度,以下是延迟加载的几种方法: 1.使用setTimeout延迟方法的加载时间 延迟加载js代码,给网页加载留出更多时间 <script type=" ...
- 虚拟机找不到本机vmnet0,vmnet8,无法连接xshell,解决方案
首先出现这个问题肯定是第一次下载虚拟机把之前的注册表覆盖了,网卡找不到,首先卸载VMware 并且将C\ProgramData下的VMware文件夹删除掉 ,下载cceaner,点击注册表清除干净,再 ...
- freemarker使用map替换ftl中相关值
ftl文件demo01.ftl <html> <head> <title>Welcome!</title> </head> <body ...
- 第3章 从Flux到Redux
第3章 从Flux到Redux 3.1 Flux 单向数据流,React是用来替换Jquery的,Flux是以替换Backbone.js.Ember.js等MVC框架为主的. actionTypes. ...
- linux ltrace-跟踪进程调用库函数的情况
当前位置:硬件 | 监测 | 内核 | Shell / 性能监测与优化 /ltrace ltrace命令是用来跟踪进程调用库函数的情况. 语法 ltrace [option ...] [command ...
- 洛谷 2048 BZOJ 2006 [NOI2010]超级钢琴
[题解] 贪心题.设五元组(mx,pos,l,r1,r2)表示最大值为mx,取得最大值的区间右端点为pos,区间左端点为l,区间右端点的可选区间为[r1,r2]. 每次从堆里拎出最大值,然后把这个区间 ...
- BZOJ 4819 Luogu P3705 [SDOI2017]新生舞会 (最大费用最大流、二分、分数规划)
现在怎么做的题都这么水了.. 题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=4819 (luogu) https://ww ...
- java 反射运用
一,获取私有的属性,方法,构造器(俗名:暴力反射) 现有一个类,属性,方法,构造器均为私有的,如何创建实例对象,更该属性值,调用方法? public class Student { private S ...
- sql 生成某个范围内的随机数
从i-j的范围内的随机数,那么公式为FLOOR(i+RAND()*(j-i+1))
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...