1

我想为 UISegmentedControl 使用自定义背景图像,例如“查找我的朋友”。以下是他们可调整大小的图像的样子:

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

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

编辑

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

我只是看不到这张图片中使用的效果和效果。我不是在问如何使用 UIEdgeInsets。

4

1 回答 1

2

这些只是 2 张图片。一个有影子一个没有……</p>

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

例如

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

要了解 UIEdgeInsets 的工作原理,请阅读: UIEdgeInsetsMake 是如何工作的?

或在 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

于 2012-09-05T13:33:15.790 回答