在过去的几个小时里,我一直在为这个问题摸不着头脑。是否可以创建一个标准的UIBarButtonItem
,其中内部有自定义图像?我想要的只是标准的蓝色按钮,但里面有一个代表偏好的图像(我自己创建的螺丝刀或齿轮)。我宁愿不使用 Photoshop 来完成此操作,因为我希望每个像素都是完美的且面向未来,以防 Apple 发布更高分辨率的 iOS 设备。
我在 GitHub 上发现了一个很棒的项目,其中包含 iOS 附带的每个图形元素,并且我提取了 Apple 本身在创建标准 UIBarButtonItems
时使用的图像。问题是,它无法以我所知道的方式调整到正确的尺寸。如果无法使用代码执行我想要的操作,那么也许有人可以告诉我如何使用此图像。
GitHub - UIKit-Artwork-Extractor
<跨度类=“__cf_email__” data-cfemail="e8bda1a6899e818f899c818786aa899aac8d8e899d849caa9d9c9c8786a8da90c698868f">[电子邮件受保护]
谢谢!
I've been scratching my head over this for the past couple of hours. Is it possible to create a standard UIBarButtonItem
with a custom image inside? All I want is the standard blue button, but with an image that represents preferences (a screwdriver or cog wheel that I'll create myself) inside of it. I'd rather not use Photoshop to do this, since I'd like every single pixel to be perfect and future proof, in case Apple releases even higher resolution iOS devices.
I've found a wonderful project on GitHub that includes every graphic element shipped with iOS, and I've extracted what appears to be the image Apple itself uses when creating standard UIBarButtonItems
. Problem is, it can't be resized to the proper dimensions in a way that I know of. In case it's not possible to do what I want with code, then maybe someone can tell me how to use this image.
GitHub - UIKit-Artwork-Extractor
[email protected]
Thanks!
发布评论
评论(2)
只需以单一颜色创建图像(仅 Alpha 通道很重要)并使用
initWithImage:style:target:action:
具有 UIBarButtonItemStyleBordered 或 UIBarButtonItemStyleDone 样式。如果您想要全彩图像,则必须使用链接的图像。秘密是通过以 Android 9 个补丁图像,而不是缩放整个图像。
Just create your image, in a single color (only the alpha channel is significant) and use
initWithImage:style:target:action:
with the UIBarButtonItemStyleBordered or UIBarButtonItemStyleDone style.If you want a full-color image, you'll have to use the image you linked. The secret is to resize it by duplicating the "middle" column and row of pixels in the style of an Android 9-patch image, rather than by scaling the entire thing.
像这样的图像可以通过使其可拉伸来使用。基本上,您希望在调整图像大小时仅拉伸图像的中间部分,而不应缩放左右端盖,以避免失真。
但是,在您的情况下,为什么不只使用
UIBarButtonItem
并将UIBarButtonItemStyleDone
或UIBarButtonItemStyleBordered
作为其样式呢?Images like that are used by making them stretchable. Basically, you want only the middle of the image to be stretched when you resize the image, while the left and right cap should not be scaled, to avoid distortion.
In your case however, why don't you just use a
UIBarButtonItem
with theUIBarButtonItemStyleDone
orUIBarButtonItemStyleBordered
as its style?