Is there an easy way to remove the stupid image shadow from a uibarbuttonitem ?
Looks like the only way is to put an UIButton within an UIBarButton. So there is no way to directly remove the shadow from an uibarbutton image.
Related
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.
I have subclassed UINavigationBar and overridden drawRect method so I can add a gradient to it. Now, I want to use the same gradient to the back button, but I don't know what is the easiest way (subclass UIButton, subclass UIBarButton item)
Thank you.
A lot of people on StackOverflow caution against subclassing UIButton.
create uibutton subclass
The easiest way to do what you want is to use [UIButton buttonWithType:UIButtonTypeCustom].
Make a transparent .png image of your button and set it as your button.image.
You can have a look here:
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
explore: http://idevrecipes.com/2011/01/12/how-do-iphone-apps-instagramreederdailybooth-implement-custom-navigationbar-with-variable-width-back-buttons/
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...
I have an UINavigationBar, and I'm trying to add the user avatar to before the text, and I want 't so it's just before, and thought if I add it with IB, if the tabBar title is longer it would look ugly, so how could I add it on the front of the navBar? It would look like this of Osfoora:
You could add UIImageView in the titleView property of UINavigationBar.
myImageView is type of UIImageView.
self.navigationItem.titleView = myImageView;
add it as a barbutton image if you are not using any barbutton.
I need to make UIBarButtonItem rounded. In xib even though the style attibute specified as bordered it displays a rectangular shape. Is there any work around to achieve this?
Regards,
Dilshan
Try to use initWithCustomView:(UIView *)customView where the customView is a custom UIButton with a round image.