안드로이드에서는 나인패치가 없는 줄 알았는데, (안드로이드에서는 작은 배경을 직선으로 늘려서 이미지가 깨지지 않고 적용) UIImage 에도 비슷한 메서드가 존재하네요.
+(UIImage*)ninePatchedImage:(UIImage*)kOriginalImg Offset:(float)kOffset{
CGSize kSize = kOriginalImg.size;
return [kOriginalImg resizableImageWithCapInsets:UIEdgeInsetsMake(aOffset, aOffset, kSize.height-aOffset, kSize.width-aOffset)];
}
resizableImageWithCapInsets
[ iOS Document Reference]
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 pixel area in size.
Availability
- Available in iOS 5.0 and later.
Declared In
UIImage.h
'옛글 > 아이폰 프로그래밍' 카테고리의 다른 글
xCode iCloud 연동 소스 배포 (0) | 2012.07.23 |
---|---|
Code signing is required for product type 'Application' in SDK 'iOS5.1' 에러처리 (0) | 2012.07.23 |
iCloud Guide (XCode iCloud 적용가이드) (0) | 2012.07.17 |
xCode iCloud iOS/MAC App에 적용하기 Part1 (0) | 2012.07.06 |
[iOS프로그래밍] NSString Split(Token 으로 자르기) (0) | 2012.07.06 |