ios-UI控件精讲之【5】-UIImage
2016-02-24 21:57
316 查看
原文:http://www.jianshu.com/p/843578f6b691
UIImage
图片资源存放
如果图片存放在assets资源管理器,最终里面所以的图片会被打包成Assets.car,在.car中的图片是不能通过imageWithContentsOfFile:来加载imageName:加载的图片要么是Assets.car中的图片,要么是资源包(mainBundle)中直接存放的图片imageWithContentsOfFile:加载的图片,只能加载资源包(mainBundle)中直接存放的图片常用创建UIImage的方法: 1.imageName: 后面传入图片的名字 2.imageWithContentOfFile: 图片的全路径 */ UIImage *image = [UIImage imageNamed:@"1"]; NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]; UIImage *image = [UIImage imageWithContentsOfFile:imagePath];.设置图片的内容模式
Scale : 比例,缩放/伸缩// 无Scale : 不可以拉伸也不可以压缩 Aspect : 保持宽度比 UIViewContentModeScaleToFill, // 伸缩图片,让整个图片可以在imageView显示出来 UIViewContentModeScaleAspectFit, // 拉伸图片,但是在拉伸的过程当中保持宽度比.并且让整个图片可以显示出来 UIViewContentModeScaleAspectFill, // 拉伸图片,但是在拉伸的过程中保持宽度比.但是需要做到图片可以填充控件 UIViewContentModeCenter,//中间 UIViewContentModeTop,//上 UIViewContentModeBottom,//下 UIViewContentModeLeft,//左 UIViewContentModeRight,//右 UIViewContentModeTopLeft, UIViewContentModeTopRight, UIViewContentModeBottomLeft, UIViewContentModeBottomRight,添加到控制器的View中
[self.view addSubview:imageView];设置超出imageView的部分就切掉
imageView.clipsToBounds = YES;
图片拉伸
// 1.普通UIImage的对象 UIImage *image = [UIImage imageNamed:@"chat_send_nor"]; // 2.通过一个方法,返回一张可拉伸图片 UIImage *resizeImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height * 0.5 - 1, image.size.width * 0.5 - 1, image.size.height * 0.5, image.size.width)]; /* UIImageResizingModeTile, // 平铺 UIImageResizingModeStretch, // 拉伸 */ //UIImage *resizeImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height * 0.5 - 1, image.size.width * 0.5 - 1, image.size.height * 0.5, image.size.width) resizingMode:UIImageResizingModeTile]; [self.btn setBackgroundImage:resizeImage forState:UIControlStateNormal];
相关文章推荐
- 通过Gradle来取的Jenkins的build
- UI美化概述
- suid seuid 当前用户ID 有效用户ID
- 5.UINavigationController
- web.xml is missing and <failOnMissingWebXml> is set to true
- iOS-UI-基本控件之UISwitch
- UICollectionView 使用 介绍
- String,StringBuffer,StringBuilder三者区别
- deque向量
- UITextField知多少
- 持续集成(CI)-build, test, and deploy & 自动化编译系统 mark & learn
- Android--UI控件的使用格式化
- iOS 开发之动画篇 - 从 UIView 动画说起
- 深入分析Parquet列式存储格式
- POJ - 3481 Double Queue
- hasshmap输出value
- ios隐藏UItableview下面多余的tableview的线条CELL / 隐藏脚视图
- @RequestParam 和@RequestBody的使用方式
- UITextView 监听 return key的改变
- LeetCode Algorithms #232 <Implement Queue using Stacks>