Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

ios - Custom background/transparent background on UIBarButtonItem?

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

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?

EDIT:

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...