Custom UINavigationBar image with default gradient and lines - ios5

I want to use custom graphics as UINavigationBar background:
[[UINavigationBar appearance]
setBackgroundImage:[UIImage imageNamed:#"tile"]
forBarMetrics:UIBarMetricsDefault];
Works fine, except I lost default gradient, white line at top and black line at bottom of the titlebar. Any ideas how to get them back?

Gave up and added gradient and lines into the texture. Of course this meant that I had to hardcode texture height as 44 pixels == navigation bar size for vertical orientation.
Not happy with the solution, but it does work without any problems.

Related

UIToolbar gradient fix

I am using UIToolbar in my project for this lock screen. Everything is fine except the gradient on the UIToolbar is very short. I mean its height is not equal. I have attached the screen shot. I want the UIToolbar to be like figure B.
Any idea how to achieve this.
Best thing you can do is setting appearance for your UIToolBar:
UIImage *gradientImage = [[UIImage imageNamed:#"upperBar.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(-4, 300, 10, 300)];
UIToolbar *toolbar = [UIToolBar appearance];
[toolbar setBackgroundImage:gradientImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Where upperBar.png is the gradient image you want.
A UIToolbar in iOS6 and earlier always draws its shine over the top 22px. If you want a bigger shine, you'll have to provide a background image using setBackgroundImage:forToolbarPosition:barMetrics:.
Two more things, though:
UIToolbar on an iPhone expects to be at the bottom of your content; if you're using it to give you a background suitable for the top, you should use a UINavigationBar instead.
The appearance of toolbars, navigation bars, and the lock screen has changed in iOS7. You may want to rethink your approach so that your app doesn't look bad in the near future.

UIToolbar to have translucent and not black color

What is the most easiest way (if possible without using drawRect, subclassing, category) to have a transparent UIToolbar with not a Black color, a color of my own choice? I know you can set the translucent property of a UIToolbar, but the color is black, I tried setting the background color but it didn't work. I tried setting the background image and it works but it is not transparent then.
Have a look at the setTintColor: method. For example:
[self.navigationController.toolbar setTintColor:[UIColor greenColor]];
Try this using IB, it should work:
set Tint color of toolbar to your choice of color.
set Alpha of toolbar to 0.5 or the according to the transparency you want.
answers with code sample can be found in this question: Couldn't UIToolBar be transparent?
seba

Obj-C, how can I add a background colour to image I'm adding to cell.imageview, its a PNG?

I am using PNG images to add icons to the rows in my tableview, using
[cell.imageView setImage:[UIImage imageNamed:#"chart.png"]];
This was not a problem before, as my images had black edges and my tableview had black rows. However, I am now providing a light color style as well as dark. So the black edges look rough.
So I thought I would draw the images with a black background.
However, I don't know how to do this?
UIImageView inherits from UIView so you can just set the backgroundColor property to show a color behind the transparant parts of your png image
[cell.imageView setBackgroundColor:[UIColor blackColor]];

how can I remove the black screen comes in my game

In the following image, there is a transparent image, but the thing is that I have to remove the black screen, but not I remove this black screen , I set the layer opacity to zero, but not get the output.???
HOw Can I remove that black image;
We need to know how you create that image.
If you are using and UIImageView set the background color to transparent.
If it is a UIView instance set background color to clear color like this
[view setBackgroundColor:[UIColor clearColor]];

Putting UIView with alpha 1 on top of UIView with alpha 0.5

I'm trying to have a modular uiview that will be placed on top of another view. The modular view has an alpha value of 0.5, and appears in the middle of the main view.
Now, I would like for text to be rendered on that modular UIView. However, whenever I:
[modularView addSubview:text]
it looks all hazy.
How can I make the text tack sharp, but keep the alpha of its parent view at 0.5?
Thanks!
Set the alpha for the background color rather than for the whole view:
[modularView setBackgroundColor:[UIColor colorWithRed:0.0
green:0.0
blue:0.0
alpha:0.5]];
This will allow any subviews to retain full opacity. The color in my code is black. Just set the RGB values for whatever color you're wanting.
You could also just use a UILabel instead of a UIView and set it's background the same way. Then you don't need to add a subview--though I'm not sure what else you have in your modularView view.
I'm doing the same on a project i'm working on, my "modalview" is on top of a fullscreen image.
My "modalview" has alpha 1.0 and the background color is black with 50% opacity.
Then the text is white, with default highlight and a dark shadow with 1.0 h and v-offset.
Hope it helps...
PS: make sure you're adding the text in front of the "modalview", not behind it ;)