UIImage常用属性和方法

一、属性

1size: reflects orientation setting. In iOS 4.0 and later, this is measured in points. In 3.x and earlier, measured in pixels。设置控件的尺寸。

@property(nonatomic,readonly) CGSize size;


2CGImage: returns underlying CGImageRef or nil if CIImage based.底层的 Quartz图像数据(只读),如果图像数据已经在内存中被清除,强行调用这个方法,可以加载回内存中的数据。加载图像数据可能会带来对性能的影响。如果 UIImage对象使用 CIImage 对象进行初始化,该属性的值是空。

@property(nullable, nonatomic,readonly) CGImageRef CGImage;


3scale:图像缩放比例。

@property(nonatomic,readonly) CGFloat scale;


4images: default is nil for non-animated images。默认没有动画图像。动画图像组。这是一个图片数组,可以通过这个属性播放动画。

@property(nullable, nonatomic,readonly) NSArray<UIImage *> *images;


5duration: total duration for all frames. default is 0 for non-animated images。播放动画的时间。
@property(nonatomic,readonly) NSTimeInterval duration;


6capInsets: The end-cap insets. (read-only)指定图片拉伸时哪个范围内的图片可以被平铺或拉伸。

@property(nonatomic,readonly) UIEdgeInsets capInsets               NS_AVAILABLE_IOS(5_0);


7resizingMode: The resizing mode of the image. (read-only)枚举值,图片缩放模式

@property(nonatomic,readonly) UIImageResizingMode resizingMode NS_AVAILABLE_IOS(6_0);


8alignmentRectInsets:布局图像位置的对齐参数(只读)

@property(nonatomic,readonly) UIEdgeInsets alignmentRectInsets NS_AVAILABLE_IOS(6_0);


9renderingMode:图片的呈现方式(只读)

@property(nonatomic, readonly) UIImageRenderingMode renderingMode NS_AVAILABLE_IOS(7_0);


10traitCollection:描述对象的特征集合(只读)

@property (nonatomic, readonly, copy) UITraitCollection *traitCollection NS_AVAILABLE_IOS(8_0);


11imageAsset:返回一个参考image asset相关联的图片。(只读)如果你从参考文件创建的图片,数据,CGImageRef或者如果图片是动画,然后imageAsset的值将是 nil。基于CIImage的图片将总是返回 nil

@property (nullable, nonatomic, readonly) UIImageAsset *imageAsset NS_AVAILABLE_IOS(8_0);


12flipsForRightToLeftLayoutDirection:一个布尔值,该值指示图像是否应该从右侧向左侧布局(只读)

@property (nonatomic, readonly) BOOL flipsForRightToLeftLayoutDirection NS_AVAILABLE_IOS(9_0);


二、常用方法

1imageNamed:load from main bundle。类方法,从main bundle加载图片。

+ (nullable UIImage *)imageNamed: (NSString *)name;


2imageWithContentsOfFile:类方法,从文件加载图片内容。

+ (nullable UIImage *)imageWithContentsOfFile: (NSString *)path;


3imageWithData:类方法,从数据加载图片内容。

+ (nullable UIImage *)imageWithData: (NSData *)data;


4imageWithCGImage:类方法,加载 CGImageRef图片

+ (UIImage *)imageWithCGImage: (CGImageRef)cgImage;


5initWithContentsOfFile:对象方法,从文件加载图片

- (nullable instancetype)initWithContentsOfFile: (NSString *)path;


6initWithData:对象方法,从数据加载图片

- (nullable instancetype)initWithData: (NSData *)data;


7imageWithCGImage::对象方法,加载 CGImageRef图片

- (UIImage *)imageWithCGImage: (CGImageRef)cgImage;


8CGImage: CGImage get方法,详情请见上面CGImage属性解释。

- (nullable CGImageRef)CGImage;


9animatedImageNamed: duration:: read sequence of files with suffix starting at 0 or 1。从01开始读取带有后缀的文件序列。创建并返回一个动画图像。

+ (nullable UIImage *)animatedImageNamed: (NSString *)name duration: (NSTimeInterval)duration;


10animatedImageNamed: duration:从一组现有的图像,创建并返回一个动画图像。

+ (nullable UIImage *)animatedImageWithImages: (NSArray<UIImage *> *)images duration: (NSTimeInterval)duration;


下面这些方法是关于绘图的:

1drawAtPoint:: mode = kCGBlendModeNormal, alpha = 1.0。在 Point这个点绘图。

- (void)drawAtPoint: (CGPoint)point;


2drawAtPoint:blendMode: alpha::在 Point这个点,以某种模式绘图。

- (void)drawAtPoint: (CGPoint)point blendMode: (CGBlendMode)blendMode alpha: (CGFloat)alpha;


3drawInRect:mode = kCGBlendModeNormal, alpha = 1.0。在某个具体位置进行绘图。

- (void)drawInRect: (CGRect)rect;


4drawInRect: blendMode:alpha::在某个具体位置,以某种模式,某种透明度进行绘图。

- (void)drawInRect: (CGRect)rect blendMode: (CGBlendMode)blendMode alpha: (CGFloat)alpha;


5drawAsPatternInRect:draws the image as a CGPattern.在某个具体位置平铺图像。

- (void)drawAsPatternInRect: (CGRect)rect;


6resizableImageWithCapInsets::创建并返回一个指定边距的图像对象。

- (UIImage *)resizableImageWithCapInsets: (UIEdgeInsets)capInsets;


7resizableImageWithCapInsets:resizingMode:创建并返回一个指定边距和伸缩模式的图片对象。

- (UIImage *)resizableImageWithCapInsets: (UIEdgeInsets)capInsets resizingMode: (UIImageResizingMode)resizingMode NS_AVAILABLE_IOS(6_0);


8imageWithAlignmentRectInsets::返回一个指定了对齐方式的图片,一个新的图片对象。

- (UIImage *)imageWithAlignmentRectInsets: (UIEdgeInsets)alignmentInsets NS_AVAILABLE_IOS(6_0);


9imageWithRenderingMode::根据渲染模式,创建一并返回一个新的图片对象

- (UIImage *)imageWithRenderingMode: (UIImageRenderingMode)renderingMode NS_AVAILABLE_IOS(7_0);


10imageFlippedForRightToLeftLayoutDirection::返回当前图片,准备水平旋转时,它会从右向左布局。

- (UIImage *)imageFlippedForRightToLeftLayoutDirection NS_AVAILABLE_IOS(9_0);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值