UIBarButtonItem 上的自定义背景/透明背景? [英] Custom background/transparent background on UIBarButtonItem?

查看:29
本文介绍了UIBarButtonItem 上的自定义背景/透明背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个效果是怎么实现的?代码片段非常受欢迎.

How is this effect achieved? Code snippets are highly welcome.

这可以在备忘录应用和 App Store 上的其他应用中看到.

This can be seen in Notes app and other apps on the App Store.

导航控制器上的按钮似乎是透明的并显示导航控制器的自定义背景,或者它们本身具有应用到它们的自定义背景.关于如何实现这一点的任何想法?

It seem that either the buttons on the navigation controller are transparent and show the custom background of the navigation controller or that they themselves have a custom background applied to them. Any ideas on how this is achieved?

这是一个来自 iPhone 的 iBooks 应用程序的示例.如您所见,不仅 UIButtons,而且分段控件都有自定义背景.我在想有一种方法可以为不同的界面元素全局设置透明度/背景.

Here is an example from the iBooks app for the iPhone. As you can see, not only the UIButtons, but also the segmented control have custom backgrounds. I'm thinking that there is a way to globally set transparency/background to different interface elements.

http://c0839932.cdn.cloudfiles.rackspacecloud.com/iBooks%201.1%20-%206.png

推荐答案

如果你想在你的应用程序中到处都有 UIBarButtonItem,你可以在 AppDelegate.m 并在您的 application:didFinishLaunchingWithOptions: 方法中,您可以编写

If you want to have UIBarButtonItem everywhere in your application, what you can do is in your AppDelegate.m and in your application:didFinishLaunchingWithOptions: method, you can write

[[UIBarButtonItem appearance] setBackgroundImage:[[UIImage alloc] init] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

这将创建一个空图像,并将 UIBarButtonItem 的背景设置为该图像.将其写入 AppDelegate 后,您将确保在您使用 UIBarButtonitem 的任何地方都具有透明背景,甚至是您的后退按钮.

This will create an empty image, and it will set UIBarButtonItem's background to that image. With writing it into AppDelegate you will make sure everywhere you are using a UIBarButtonitem it will have transparent background, even your back buttons.

这篇关于UIBarButtonItem 上的自定义背景/透明背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆