0
点赞
收藏
分享

微信扫一扫

resizableImageWithCapInsets

肉肉七七 2022-08-08 阅读 64


stretchableImageWithLeftCapWidth:topCapHeight:

resizableImageWithCapInsets:

对比:

 

1. stretchableImageWithLeftCapWidth:topCapHeight: 在iOS5中已被废弃。它只能以1*1像素进行拉伸。

​​

resizableImageWithCapInsets_ios

​​

2. resizableImageWithCapInsets: 重复一块区域,而不是1*1像素。

resizableImageWithCapInsets_sed_02

resizableImageWithCapInsets:

Creates and returns a new image object with the specified cap insets.

- (UIImage *)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.

During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the pixel area not covered by the cap in each direction is tiled, left-to-right and top-to-bottom, to resize the image. This technique is often used to create variable-width buttons, which retain the same rounded corners but whose center region grows or shrinks as needed. For best performance, use a tiled area that is a 1x1

Availability

  • Available in iOS 5.0 and later.

Declared In

UIImage.h

 

stretchableImageWithLeftCapWidth:topCapHeight:

Creates and returns a new image object with the specified cap values. (Deprecated in iOS 5.0. Deprecated. Use the resizableImageWithCapInsets: instead, specifying cap insets such that the interior is a 1x1area.)

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

Parameters

leftCapWidth

The value to use for the left cap width. Specify 0 if you want the entire image to be horizontally stretchable. For a discussion of how a non-zero value affects the image, see the leftCapWidth

topCapHeight

The value to use for the top cap width. Specify 0 if you want the entire image to be vertically stretchable. For a discussion of how a non-zero value affects the image, see the topCapHeight

Return Value

A new image object with the specified cap values.

Discussion

During scaling or resizing of the image, areas covered by a cap are not scaled or resized. Instead, the 1-pixel wide area not covered by the cap in each direction is what is scaled or resized. This technique is often used to create variable-width buttons, which retain the same rounded corners but whose center region grows or shrinks as needed.

You use this method to add cap values to an image or to change the existing cap values of an image. In both cases, you get back a new image and the original image remains untouched.

Availability

  • Available in iOS 2.0 and later.
  • Deprecated in iOS 5.0.

Related Sample Code

举报

相关推荐

0 条评论