UIImage - resizableImageWithCapInsets & - resizableImageWithCapInsets:resizingMode

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值