UIImage——特殊UIImage

原创 2016年08月29日 14:31:36

animated

// animated images. When set as UIImageView.image, animation will play in an infinite loop until removed. Drawing will render the first image

+ (nullable UIImage *)animatedImageNamed:(NSString *)name duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);  // read sequence of files with suffix starting at 0 or 1
+ (nullable UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0); // sequence of files
+ (nullable UIImage *)animatedResizableImageNamed:(NSString *)name capInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(6_0);
+ (nullable UIImage *)animatedImageWithImages:(NSArray<UIImage *> *)images duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);

@property(nullable, nonatomic,readonly) NSArray<UIImage *> *images   NS_AVAILABLE_IOS(5_0); // default is nil for non-animated images
@property(nonatomic,readonly) NSTimeInterval duration NS_AVAILABLE_IOS(5_0); // total duration for all frames. default is 0 for non-animated images
注意:
  • name只是一个base name,UIImage会添加0~1024后缀拼成完整文件名从bundle中load
  • UIImage中的所有UIImage共享同一个size和scale,取images中第一张图片的size和scale
  • images中所有UIImage使用同一capInsets和resizingMode

right-to-left layout

- (UIImage *)imageFlippedForRightToLeftLayoutDirection NS_AVAILABLE_IOS(9_0);
@property (nonatomic, readonly) BOOL flipsForRightToLeftLayoutDirection NS_AVAILABLE_IOS(9_0);
注意:
  • 只是设置flipsForRightToLeftLayoutDirection属性值为YES,返回的还是原图像
  • 只有当flipsForRightToLeftLayoutDirection为YES而且环境为right-to-left时(比如国家语言环境为阿拉伯,阿拉伯阅读习惯从右向左),UIImage才会以right-to-left layout显示(相当于水平反转)

render mode

// Create a version of this image with the specified rendering mode. By default, images have a rendering mode of UIImageRenderingModeAutomatic.
- (UIImage *)imageWithRenderingMode:(UIImageRenderingMode)renderingMode NS_AVAILABLE_IOS(7_0);
@property(nonatomic, readonly) UIImageRenderingMode renderingMode NS_AVAILABLE_IOS(7_0);
/* Images are created with UIImageRenderingModeAutomatic by default. An image with this mode is interpreted as a template image or an original image based on the context in which it is rendered. For example, navigation bars, tab bars, toolbars, and segmented controls automatically treat their foreground images as templates, while image views and web views treat their images as originals. You can use UIImageRenderingModeAlwaysTemplate to force your image to always be rendered as a template or UIImageRenderingModeAlwaysOriginal to force your image to always be rendered as an original.
 */
typedef NS_ENUM(NSInteger, UIImageRenderingMode) {
    UIImageRenderingModeAutomatic,          // Use the default rendering mode for the context where the image is used
    
    UIImageRenderingModeAlwaysOriginal,     // Always draw the original image, without treating it as a template
    UIImageRenderingModeAlwaysTemplate,     // Always draw the image as a template image, ignoring its color information
} NS_ENUM_AVAILABLE_IOS(7_0);

alignment

// Support for constraint-based layout (auto layout)
// The alignmentRectInsets of a UIImage are used by UIImageView and other UIView and UIControl
//  subclasses that take custom images to determine the view's alignment rect insets for
//  constraint-based layout.
// The default alignmentRectInsets are UIEdgeInsetsZero.
- (UIImage *)imageWithAlignmentRectInsets:(UIEdgeInsets)alignmentInsets NS_AVAILABLE_IOS(6_0);
@property(nonatomic,readonly) UIEdgeInsets alignmentRectInsets NS_AVAILABLE_IOS(6_0);

resizable

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets NS_AVAILABLE_IOS(5_0); // create a resizable version of this image. the interior is tiled when drawn.
- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0); // the interior is resized according to the resizingMode

@property(nonatomic,readonly) UIEdgeInsets capInsets               NS_AVAILABLE_IOS(5_0);   // default is UIEdgeInsetsZero for non resizable images
@property(nonatomic,readonly) UIImageResizingMode resizingMode NS_AVAILABLE_IOS(6_0); // default is UIImageResizingModeTile
/* UIImage will implement the resizing mode the fastest way possible while
 retaining the desired visual appearance.
 Note that if an image's resizable area is one point then UIImageResizingModeTile
 is visually indistinguishable from UIImageResizingModeStretch.
 */
typedef NS_ENUM(NSInteger, UIImageResizingMode) {
    UIImageResizingModeTile,
    UIImageResizingModeStretch,
};
注意:
  • 对单一UIImage应用capInsets和resizingMode

left cap&top cap

// use resizableImageWithCapInsets: and capInsets.

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight __TVOS_PROHIBITED;
@property(nonatomic,readonly) NSInteger leftCapWidth __TVOS_PROHIBITED;   // default is 0. if non-zero, horiz. stretchable. right cap is calculated as width - leftCapWidth - 1
@property(nonatomic,readonly) NSInteger topCapHeight __TVOS_PROHIBITED;   // default is 0. if non-zero, vert. stretchable. bottom cap is calculated as height - topCapWidth - 1
注意:
  • 如果leftCapWidth为0,整个宽度拉升,如果leftCapWidth不为0,一个像素宽度拉伸,topCapHeight类似
版权声明:本文为博主原创文章,未经博主允许不得转载。

UIImage常用属性和方法

一、属性 1、size: reflects orientation setting. In iOS 4.0 and later, this is measured in points. In 3.x...

UIImage的扩展方法——裁剪图片和等比列缩放图片-翻转-圆形等

首先创建一个UIImage类别,如下: @interface UIImage(UIImageScale)  -(UIImage*)getSubImage:(CGRect)rect;  -...

iOS学习笔记-033.数据的读取——NSString和UIImage的保存

数据的读取NSString和UIImage的保存 一NSString的保存 二UIImage的保存 三代码 四图示数据的读取——NSString和UIImage的保存一、NSString的保存注意:N...

iOS开发笔记之二十七——UIImage图片的移动、旋转、缩放和裁剪

开发中经常会需要用到图片(UIImage)的编辑功能,例如图片的缩放、移动、旋转、裁剪等;这些基本功能很常用,近期的项目中也有这么一个需求,需要做固定区域的裁剪。图片来源是iphone手机相册或者相机...
  • lizitao
  • lizitao
  • 2014年12月09日 20:35
  • 7009

iOS开发 ☞ UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用

简介:有时候我们只是想把图片部分拉伸,而不是全部拉伸,那么就要用到下面这个函数,并附上实例验证 - (UIImage *)stretchableImageWithLeftCapWidth:(NSI...

UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用

UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用

UIImage的扩展方法——裁剪图片和等比列缩放图片

UIImage的扩展方法——裁剪图片和等比列缩放图片 首先创建一个UIImage类别,如下:  @interface UIImage(UIImageScale)   -(UIIm...

UIIMAGE处理

  • 2014年09月02日 15:47
  • 17KB
  • 下载

IOS:UIImage的剪切,尺寸缩小、压缩、添加水印

不多说了,直接贴代码吧 - (void)viewDidLoad {     [super viewDidLoad];          UIImage *image = [UI...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UIImage——特殊UIImage
举报原因:
原因补充:

(最多只允许输入30个字)