How to remove black background on UITabBar - ios

I want to create the TabBar which align at center no matter what how many tabitem is.
The final result may be look like the image below.
I can set width of TabBar by using
UITabBar *tabBar = self.tabBarController.tabBar;
CGRect rectAdjust = CGRectMake(tabBar.frame.origin.x, tabBar.frame.origin.y, 160.0f, tabBar.frame.size.height);
tabBar.frame = rectAdjust;
But I cannot remove the black background on UITabBar(on the right side in below image) even though I already set the size of TabBar to be half the screen's width.
Is there any way to solve this?
Thanks.

Instead of reinventing the wheel, you could take a look at this control at the CocoaControls website:
ALTabBarController for iOS
It is more customizable than the traditional TabBar

You could set an image for the table bar that has caps on either side and a few pixels in between, then make it a resizeable image like so:
UIImage *background = [[UIImage imageNamed:#"ImageName.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
Then set it as the background image of the tab bar:
tabBar.backgroundImage = background;
And it should resize to the image you need.
Then set the background color of the tab bar to clear:
tabBar.backgroundColor = [UIColor clearColor];

Related

self.navigationController.navigationBar.translucent = NO; create an extra gap after navigationBar

Let me explain my situation first. I set the UINavigationBar color in my appDelegate Like:
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:255.0f/255.0f green:87.0f/255.0f blue:10.0f/255.0f alpha:1]];
Now in my some viewController the translucent of UINavigationBar set as YES.
self.navigationController.navigationBar.translucent = YES;
That's why there is a shade over my UINavigationBar. It wasn't showing the exact color. As a solution, I set translucent from YES to NO. It is showing the exact color now, But I am facing that some of my view completely gone from my interface. Here, let me tell you one thing that, so many of views here, is positioned by programmatically, so I am afraid I can't just move every of my viewControllers view 64 px high. Just wondering is there any solution to solve the thing. I try with opaque, but no luck. If any one understand my problem please share the solution if you have. Thanks a lot in advance.
From iOS7 if you use a translucent bar ( in UINavigationController or UITabbarController) the hosted view controller has as default behavior to extend under them. If you say to set the bar as translucent the color of it it will be a combination of the view under it and bat color. That is normal and the only way is to set translucency to no or apply a background image to navigation bar.
Applying frames manually will lead to unexpected result under auto layout, you must use constraints.
[UPDATE]
To create a background image from a solid color you can use that method, the image is 1px square, but there is no problem because it can be stretched or tiled to cover the entire area:
+ (UIImage *) imageWithColor:(UIColor*) color {
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return colorImage;
}
If you see and extra gap is probably because you have also set automaticallyAdjustScrollViewInset to YES, try setting it NO. This property add and extra inset to your view or your vfirst view subview if it inherits from a UIScrollView
Its late, but i face same issue, and i resolved it by making UINavigationbar none on Viewcontroller in storyboard, and resized the view to start from 0,0

View controller with background image and transparency xamarin

I kind of stuck with a design issue in iOS.
I have a controller with a background image, nothing special.
this.View.BackgroundColor = UIColor.FromPatternImage (UIImage.FromFile ("Images/ballons.jpg"));
On top of the controller I have a view with a background color (white) that is semi-transparent.
this.Frame = new System.Drawing.RectangleF (0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
this.BackgroundColor = UIColor.White;
this.Alpha = 0.5f;
Now the issue is if I add a button or any other controls in my view they also becomes transparent...so am I thinking wrong here...?
I would like the controller to have a background image, the view a white semi-transparent background and all the controls (buttons, images) not to be transparent at all...
Do not change the Alpha of the view, since that will change the transparency of all its elements/subviews. Just set its BackgroundColor to a semi-transparent color using UIColor.FromWhiteAlpha(1, 0.5).

How can I set the correct Nav Bar tint color?

I am creating a title view in my navigation bar. I designed my title view with background view color R:255 G:182 B:22 (on photoshop). In my storyboard, I've set the navigation bar tint color with the same RGB code, default style and translucent checked.
I put my image on my navigation title using:
UIImage *titleImage = [UIImage imageNamed:#"Icon-Small-40.png"];
self.navigationItem.titleView = [[UIImageView alloc]initWithImage:titleImage];
When I run the app, you can clearly see a square icon in the title view. The title view has a slightly darker background. I want to make the background the same color. I get the feeling that it has something to do with some storyboard setting but I can't find the issue.
the view has a tintColor property, so
self.navigationItem.titleView.tintColor = ...
Below answer for your navigation bar tint color
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
Trying to make colours match up like this can be maddening. Colour space problems aside, the actual colour of the navigation bar isn’t guaranteed by the API to be the same as its barTintColor. You might find it easier to give the title image a transparent background.

clear color background nav bar, but still float above all the contents

I am a new iOS developer, i found some apps that can have a totally transparent nav bar, but still float above all the content, such as the app has a very nice background picture, and the nav bar is transparent, so you can see the entire background, but there is a scroll view on the navigation view controller. when scroll, it still goes under the nav bar.
when i try it, i set up my nav bar background as transparent like this
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor clearColor]] forBarMetrics:UIBarMetricsDefault];
but my scroll view will be totally visible when it goes under nav bar. I don't like that, does any one know how to make the nav bar transparent but still kind of floating on everything?
Thank you guys for the reputations, here is a screen shot from Yahoo weather their nav bar does exactly what i want.
But when i set the clear background to it, it becomes like this.
I am not 100% sure how Yahoo did it, but i can kind of fake that effect like this
I am inspired by BTGlassScrollView (https://github.com/BTLibrary/BTGlassScrollView) the approach i am using have several steps:
1.> set up your navigation controller like this:
Put your background image view first
Then add a wrapper view for your scroll view, and set the wrapper view background as Transparent (this wrapper view is very important, we have to fake the effect on this wrapper view)
drag your scroll view into the wrapper view, and set your scroll view background as Transparent as well.
2.> set up all the outlets for scroll view, wrapper view and background image view
3.> You might also want to hide the nav bar shadow image, here is the code, just in case if you need it
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
4.> Then paste this method into your class
- (CALayer *)createViewMaskWithSize:(CGSize)size startGradientAt:(CGFloat)start endGradientAt:(CGFloat)end
{
CAGradientLayer *mask = [CAGradientLayer layer];
mask.anchorPoint = CGPointZero;
mask.startPoint = CGPointMake(0.5f, 0.0f);
mask.endPoint = CGPointMake(0.5f, 1.0f);
mask.colors = #[(id)[UIColor clearColor].CGColor, (id)[UIColor clearColor].CGColor, (id)[UIColor whiteColor].CGColor, (id)[UIColor whiteColor].CGColor];
mask.locations = #[#0.0, #(start/size.height), #(end/size.height), #1.0f];
mask.frame = CGRectMake(0, 0, size.width, size.height);
return mask;
}
The purpose for this method is to create a mask layer with a clear to white gradient on it.
5.> last step, simply add that to your wrapperView.layer.mask like this
// 64 in here is the position where the fade effect should start, and 80 is where the gradien should end
// you can change those 2 numbers and see different effects
self.scrollViewWrapperView.layer.mask = [self createViewMaskWithSize:self.scrollViewWrapperView.frame.size startGradientAt:64 endGradientAt:80];
The wrapper view is the key in this case, the nav bar won't work without it. and remember DO NOT put the background image view into the wrapper view, they should be on the same level, but background image under the wrapper view.
This is a very rough mock ups, but hope this gives you some ideas.

adjusting view after hiding navigation bar

I have an app that has both navigationbar and toolbar on display with various buttons...
I have an imageview that will act as a help overlay (like you see in many apps these days) that is semi transparent with arrows pointing to the buttons on the bars plus actual view content.
First attempt displays the imageview in the view area but leaving the bars in place...not good!
So next attempt I have included the bars as part of the imageview and add this to take up the entire screen, so far so good. I then hide the bars but oh no.....the view moves up 44 pixels (as expected)
Problem is no matter what I do I cannot get the view to move down the 44 pixels?
So the imageview displays the bars giving the illusion the overlay (imageview) is on top, but the view in between is out of whack!
Does anyone know how to resolve this?
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 750, 1024)];
iv.userInteractionEnabled = YES;
iv.image = [UIImage imageNamed:#"myimage.png"];
UIWindow *window = self.view.window;
[window addSubview:iv];

Resources