如何创建一个UIButton来呈现与UIBarButtonItem相同的效果?
我想创建一个 UIButton,但与 UIBarButtonItem 的外观相同。怎么办呢??
I want to create a UIButton, but same appearence of a UIBarButtonItem. How to do it??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
发现这个有用
https://github.com/0xced/UIKit-Artwork-Extractor
Found this useful
https://github.com/0xced/UIKit-Artwork-Extractor
在导航栏之外,创建与
UIBarButton
样式相同的按钮的唯一方法是自己实际创建必要的背景图像。没有任何类可供您用于此目的(显然有一个类,但它被视为私有 API,使用它将使您的应用程序被拒绝)。Outside of a navigation bar, the only way to create a button with the same style as a
UIBarButton
is to actually create the necessary background images yourself. There is no class that you may use for this (there is a class, obviously, but it's considered private API and using it will get your app rejected).您可以通过将按钮图像上的 renderMode 设置为 UIImageRenderingModeAlwaysTemplate 来实现此目的。这将使它继承其祖先视图的tintColor。
以下是如何在 Swift 中执行此操作(无论如何,对于一种控制状态):
You can do it by setting the renderMode on the button's image to
UIImageRenderingModeAlwaysTemplate
. That will make it inherit the tintColor of its ancestor view.Here's how to do it in Swift (for one control state, anyway):
我通过另一个论坛找到了这个.. GradientButton 类。
http://code.google.com/p/iphonegradientbuttons/downloads/list
I found this via another forum .. a GradientButton class.
http://code.google.com/p/iphonegradientbuttons/downloads/list
可能有点晚了,但万一有人遇到这个问题,还有另一种不使用图像的可能性。我用 QuartzCore 代替。
这就是我所做的:
希望对某人有帮助
Might be a little late but in case someone comes accross this, there is also another possiblity without using images. I use QuartzCore instead.
This is what i do:
Hope it helps someone