如何在这样的代码中绘制可调整大小的UIImage?

时间:2012-09-05 13:17:57

标签: ios core-graphics uisegmentedcontrol

我想为UISegmentedControl使用自定义背景图片,例如“Find My Friends”。以下是他们可调整大小的图片的样子:

source http://feedzr.com/source.png source http://feedzr.com/inwork.png

如何在Core Graphics中创建复杂的阴影效果?

修改

底部图像就是在真实的UISegmentedControl中使用皮革背景时上面的样子。在可调整大小的图像中有很多效果,如: 底部光泽,顶部内部阴影和从顶部到底部的部分渐变。

我只是看不出&在这张图片中使用了什么效果。我不是在问如何使用UIEdgeInsets。

1 个答案:

答案 0 :(得分:2)

这些只是2张图片。一个没影子的人......

您必须使用CapInsets创建这些图像以使其可调整大小

例如

UIImage *buttonImage = [[UIImage imageNamed:@"yourImage"]  
   resizableImageWithCapInsets:UIEdgeInsetsMake(1, 11, 0, 20)];

要了解UIEdgeInsets如何工作: How does UIEdgeInsetsMake work?

或者在Apple Doc中:

UIEdgeInsetsMake
Creates an edge inset for a button or view.

UIEdgeInsets UIEdgeInsetsMake (
   CGFloat top,
   CGFloat left,
   CGFloat bottom,
   CGFloat right
);
Parameters
top
The inset at the top of an object.
left
The inset on the left of an object
bottom
The inset on the bottom of an object.
right
The inset on the right of an object.
Return Value
An inset for a button or view

Discussion
An inset is a margin around the drawing rectangle where each side (left, right, top, and bottom) can have a different value.

Availability
Available in iOS 2.0 and later.
See Also

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html