UIImage - resizableImageWithCapInsets & - resizableImageWithCapInsets:resizingMode

来源:互联网 发布:淘宝面具 编辑:程序博客网 时间:2024/05/23 17:59
UIImage - resizableImageWithCapInsets:
Creates and returns a new image object with the specified cap insets.

Declaration
SWIFT
func resizableImageWithCapInsets(_ capInsets: UIEdgeInsets) -> UIImage
OBJECTIVE-C
- (UIImage * _Nonnull)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
Parameters
capInsets
The values to use for the cap insets.
Return Value
A new image object with the specified cap insets.

Discussion
You use this method to add cap insets to an image or to change the existing cap insets of an image. In both cases, you get back a new image and the original image remains untouched. For example, you can use this method to create a background image for a button with borders and corners: when the button is resized, the corners of the image remain unchanged, but the borders and center of the image expand to cover the new size.

iOS uses different rendering techniques, with different performance characteristics, depending on the size of each resizable area in the image:

If resizable areas have a width or height of 1 pixel—that is, a horizontally resizable area is 1 pixel wide, a vertically resizable area is 1 pixel tall, or the center region of the image is 1 x 1 pixel—iOS draws the image by stretching the 1-pixel region. This mode provides the fastest performance (for nonzero cap insets).

If resizable areas have a width or height greater than 1 pixel, iOS draws the image by tiling the region. This mode provides reduced performance, but can be useful for images with textured (rather than solid-color) content in their resizable areas.

If the entire image is resizable—that is, the capInsets parameter is UIEdgeInsetsZero—and its size is greater than 1 x 1 pixel, iOS draws the image by tiling the entire image. This mode is faster than the tiling mode for nonzero cap insets.

To instead directly control the resizing mode, use the resizableImageWithCapInsets:resizingMode: method.

Availability
Available in iOS 5.0 and later.



UIImage - resizableImageWithCapInsets:resizingMode:
Creates and returns a new image object with the specified cap insets and options.

Declaration
SWIFT
func resizableImageWithCapInsets(_ capInsets: UIEdgeInsets,
                    resizingMode resizingMode: UIImageResizingMode) -> UIImage
OBJECTIVE-C
- (UIImage * _Nonnull)resizableImageWithCapInsets:(UIEdgeInsets)capInsets
                                     resizingMode:(UIImageResizingMode)resizingMode
Parameters
capInsets
The values to use for the cap insets.
resizingMode
The mode with which the interior of the image is resized.
Return Value
A new image object with the specified cap insets and resizing mode.

Discussion
This method is exactly the same as its counterpart resizableImageWithCapInsets: except that the resizing mode of the new image object can be explicitly declared. You should only call this method in place of its counterpart if you specifically want your image to be resized with the UIImageResizingModeStretch resizing mode.

Availability
Available in iOS 6.0 and later.


方法 resizableImageWithCapInsets: 在版本 5.0 以后使用。
方法 resizableImageWithCapInsets:resizingMode: 在版本 6.0 以后使用。
0 0
原创粉丝点击