Change UIToolbar Shadow Color For UIBarButtonItem - iphone

I am styling a UIToolbar by changing the tint color of it and the tint color of its UIBarButtonItem subviews. I have it working except that I can't find how to change the the shadow color from a dark color to a light color for the individual bar button items (see example, bar button items look blurry):
How can I change the shadow on the UIBarButtonItem with style UIBarButtonItemStylePlain to be white? I've uploaded a sample project here.

The final solution was to add the buttons as UIButton contained in UIBarButtonItem and include any shadows in the PNG used for the UIButton image.

In the UIBarButtonItem Class Reference there isn't a single mention of the word "shadow"
You use an image for the shadow, not a UIColor
Some source code examples can be found # cocoaControls.com
For the UIBarButtonItem appearance only the 2 images and colors can be changed:
setBackgroundImage:forState:barMetrics:
Sets the background image for a given state and bar metrics.
- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics
For the UIToolBar:
For adding your own custom shadow look at this StackOverflow
post
For using cocoa-predefined functions look at UIToolBar Class
Reference
setShadowImage:forToolbarPosition:
Sets the image to use for the toolbar shadow in a given position.
(void)setShadowImage:(UIImage *)shadowImage forToolbarPosition:(UIToolbarPosition)topOrBottom
shadowImageForToolbarPosition:
Returns the image to use for the toolbar shadow in a given position.
(UIImage *)shadowImageForToolbarPosition:(UIToolbarPosition)topOrBottom
I don't know what else to say, there isn't a shadow method for the UIBarButtonItem.
I hope this is self explanatory.

Related

How to create a gray overlay for a UIButton in touched state programmatically?

I would like to make a generic class that when tapped, makes the element grayish.
Facebook's app is the perfect example of what I want to achieve. All their links and images become gray when tapped.
I can only guess that they are subclassing UIButton.
I have made my button's style UIButtonTypeCustom to get rid of the rounded border. Beyond this, I don't know how to have the gray overlay because I see no such property in the documentation.
Its simple:
#define TAG_GRAYVIEW 5671263 // some random number
// add the gray overlay
UIView *grayView = [[UIView alloc] initWithFrame:button.bounds];
grayView.backgroundColor = [UIColor grayColor];
grayView.tag = TAG_GRAYVIEW;
[button addSubview:grayView];
// remove the gray overlay
UIView *grayView = [button viewWithTag:TAG_GRAYVIEW];
[grayView removeFromSuperview];
I think you need to use a semi transperant grey image PNG file. You need to then set Image of button in Highlighted state.
Also note that both the images for Normal State and Highlighted State need to have the images with titles on them.
As once we set the image to button, btn.titleLabel.text won't be displayed.
So you can have a image with transperant background and title on it for Normal state. And an grey image with title on it for Highlighted State.
Code for doing it programmatically is
[btn setImage:#"Transperant.png" forState:UIControlStateNormal];
[btn setImage:#"Grey.png" forState:UIControlStateHighlighted];
Hope this helps you.
The default UIButton masks the opaque content using a gray highlight. For example when using a transparent png, only the parts that contain non-transparent pixels will be grayed out on touch. The default UIButton highlight has no effect on subviews/sublayers, and will only work on provided images. What you see in the Facebook app is probably just a UIWebView highlight, possibly customized using css.
To create something similar using your own control (to prevent the overhead of a UIWebView) you should probably create your own UIControl subclass and highlight the content on touch using a transparent CALayer. You can even mask the CALayer to only highlight the actual contents, instead of a rectangular shape.
Also see my stackoverflow post on creating custom controls for iOS by subclassing UIControl.
Try setting the button up something like this.
*mind you I didn't create the image for this example.
Set your button type to custom, and in "State Config" select "Highlighted" from there you will want to set the image of the button to be a semi-transparent grey image. There are probably several other ways to achieve this same effect but this one should be nice and simple.

UITabBar fully transparent

In XCode I am using the interface builder (StoryBoard) to lay out most of my layout. However I want some custom drawing on this. This works quite well.
There is however a problem what I am facing. I have a "bite" out of the active tab. (see http://cl.ly/Efno ) I want this bite fully transparent. (I have set an pink background color to see what part I want transparent which is not transparent.)
How I have changed the look and feel is the following.
Set the UITabBar class to my own class in the interface builder for the corresponding tabbar.
In the awakeFromNib of that class I have set the label position and image and selected image of each tabbar item. Like so
[tabBarItem setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:image];
Each image fully covers the entire tabbar in height and has the width of the tab item itself.
Set the background image of the tabbar to none (a fully transparent image)
Set the background color of the tabbar to a fully transparent color (now I have a pink color set to see where it goes wrong)
In the interface builder uncheck "opaque" for the tabbar.
However, it is not transparent, the pink part is black. How can I make this transparent?
Thanks
Have a look at the appearance proxy for UITabBar, you might be able to do what you want there without having to use a custom subclass. There are tons of properties you can access and change. You could set the relevant properties in the app delegate. It is iOS5 only though, but I gather that you are using that already, since you mentioned storyboards.
E.g.
UIImage *tabBarBackground = [UIImage imageNamed:#"tabBarBackground.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:127.0/255.0 green:186.0/255.0 blue:235.0/255.0 alpha:1.0]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tabBarItemSelected.png"]];

how to Change a Rounded Rect UIbutton background color

how to Change UIbutton background color??
I try it on IB, but it doesn't work. only changes it for custom button.
I would like to change the white color on the rounded rect button.
Or instead how to make a custom button whit rounded corners
thanks!
Rounded rect button's color can be changed to any color with the background color property in IB as well as through coding, but can not change its color to transparent color easily. For that, you better use a custom button with either rounded image or set layer as demonstrated in the example and don't forget to add Quartz Core framework in you project as well as to import it in your class.
UIBUtton *myBtn = [UIButton buttonWithType:UIbuttonTypeCustom];
myBtn.frame = frame; //your desired size
myBtn.clipsToBounds = YES;
myBtn.layer.cornerRadius = 5.0f;
[self.view addSubView:myBtn];
You may find it difficult to adjust the default button. However you can use any view you want with a custom button.
Here's an article on creating views with rounded corners:
http://iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html
You also may look at a program called Opacity, which allows you to create a a lot of customized standard iOS interface art/buttons.
http://likethought.com/opacity/
UIButton *tagButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
and have a look at this... that my do the trick.. i did it for mine.
You can use a custom UIButton with custom images for backgroundimage for each state. Just make the different states of your rounded button in photoshop for example.
You can use Custom button But for that use the image of button of white rounded corners
so it will be look like white round rectangle button
You should use UIButtonTypeCustom, instead of any other.

How to create custom UIBarButtonItem without glossy effect

I use Three20 to create UIBarButtonItem as shown in this StackOverFlow question:
Custom UIBarButtonItem with quartz
now I what that UIBarButtonItem have no glossy effect and can have different color (light color and dark color).
Do you know how to do it?
UPDATE:
and I would like to do it without using images.
You can always use initWithCustomView on UIBarButtonItem and using it you can basically put in that view what ever you want - TTButton, UIButton, custom UIView, etc...

How To Make A UIButton Match My NavBar?

I have a custom color navbar using the following code:
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:35/255.0 green:161.0/255.0 blue:202.0/255.0 alpha:1.0];
I want to make a UIButton with the exact same color and gradient that the navbar is. I've tried in photoshop but don't know how to make the 2 tone graident style.
Is there anyway to do this programatically? I already have the buttons set up in IB.
Check out this link. There you can find a class that extends UIButton, so that you can change the color of your buttons and even do some gradient.