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 ...
随机推荐
- JavaScipt30(第十八个案例)(主要知识点:Array.prototype.map)
承接上文,这是第十八个案例,中间的十到十八我直接看了答案,因为有些例子从他打开的页面看不出他要做什么. 附上项目链接: https://github.com/wesbos/JavaScript30 这 ...
- 重启rsyncd
systemctl restart rsyncd.service
- react native 从头开始
1.react-native run-android 报错SDK location not found. Define location with sdk.dir in the local.prope ...
- 电子笔记本的思考(1)(ver0.2)
章节:电子笔记本的思考(1) 陶哲轩在<解题·成长·快乐——陶哲轩教你学数学>中着重强调,用纸笔来“缓存”思维对于数学解题的重要性: 用选定的符号表达你所知道的信息,并画一个示意图.把 ...
- c++运行程序闪退
以最简单程序为例 法一:在主函数末尾下一行getchar();即可.需要注意的是这种方法并不适合所有程序, 法二:<1>先在程序开头加上头文件#includ ...
- UVA - 1615 Highway(贪心-区间选点问题)
题目: 给定平面上n(n≤105)个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个点,都有一个选出的点离它的欧几里得距离不超过D. 思路: 先自己造区间,然后贪心选点就可以了.之前做过一 ...
- Python面向对象类的特殊成员方法
类的特殊成员方法:1.__doc__ : 打印类下面的注释 2.__module__和__class__:from lib.aa import C输出类被导出的模块名lib.aa,输出类的模块名和类名 ...
- linux less-分屏上下翻页浏览文件内容
博主推荐:获取更多 linux文件内容查看命令 收藏:linux命令大全 less命令的作用与more十分相似,都可以用来浏览文字档案的内容,不同的是less命令允许用户向前或向后浏览文件,而more ...
- Python字符串(Python学习笔记02)
字符串 Python 3 中的字符串可以使用双引号或单引号标示,如果字符串出现引号,则可以使用 \ 来去除引号标示字符串的作用. 几种字符串的表示方法: str1 = "hello" ...
- 第九节:web爬虫之urllib(五)
第四个模块 robotparser: 主要是用来识别网站的 robots.txt 文件,然后判断哪些网站可以爬,哪些网站不可以爬的,其实用的比较少.