I am trying to remove shadow from the navigationbar but not get success (iOS7).
Used the code below,
Method 1
[self.navigationController.navigationBar setBackgroundImage:image
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
Method 2
for (UIView *view in self.navigationController.navigationBar.subviews) {
for (UIView *view2 in view.subviews) {
if ([view2 isKindOfClass:[UIImageView class]]) {
[view2 removeFromSuperview];
}
}
}
Method 3
[self.layer setMasksToBounds:YES];
Method 4
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
Method 5
[self.navigationController.navigationBar setBackgroundImage:image
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage imageNamed:#"transparentpx.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)]];
None of them worked for me.
Could any one suggest new method..
Using an empty image hasn't worked for me.
I had to use a 1x1 pixel transparent image as the shadow image in order for it to appear invisible.
[self.navigationBar setShadowImage:[[UIImage imageNamed:#"navbar-shadow"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)]];
Have you tried this?
self.navigationController.navigationBar.layer.opacity = 0;
self.navigationController.navigationBar.layer.borderWidth = 0;
self.navigationController.navigationBar.layer.borderColor = [[UIColor clearColor] CGColor];
Related
I have been trying to make transparent tabBar background, but something, called UITabBarBackgroundView, is present and has white background.
How can i access it?
I don't think there is a direct way of doing this. You will have to create an illusion of transparency here. One way to do this is to set an image in tab bar. You can add following category on UITabBarController and call it
- (void) setBackgroundImage:(UIImage *)image
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
imageView.backgroundColor = [UIColor colorWithPatternImage:image];
[self.view addSubview:imageView];
[self.view sendSubviewToBack:imageView];
[self.view setOpaque:NO];
[self.view setBackgroundColor:[UIColor clearColor]];
}
Another way (image way only :)):
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"]];
I have followed the top guides on how to make my top bar transparent, but the best I can get is translucent. I am also trying to get the buttons white, not default blue. What am I missing?
#implementation FindAssetLocationMapViewController
- (void) viewWillAppear:(BOOL)animated {
self.edgesForExtendedLayout = UIRectEdgeAll;
self.extendedLayoutIncludesOpaqueBars = true;
[self.navigationController.navigationBar setTranslucent:YES];
self.navigationController.navigationBar.shadowImage = [UIImage new];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.view.backgroundColor = [UIColor redColor];
}
Images are below. Should I take screenshots of the FindAssetLocationMapViewController attributes as well? Just to clarify, the nav controller and nav bar attributes do not have a class associated with them.
Try this code in your app delegate, then remove the code you have:
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0, 0, 1, 1);
// create a 1 by 1 pixel context
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Place this inside application:didFinishLaunchingWithOptions:
//create background images for the navigation bar
UIImage *clear = [AppDelegate imageWithColor:[UIColor clearColor]];
//customize the appearance of UINavigationBar
[[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsCompact];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
I'm doing some changes to the Navigationbar with appearance in appdelegate.
This is my method:
-(void) setAppearance{
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:#"AvantGarde-ExtraLight" size:18] forKey:NSFontAttributeName];
[titleBarAttributes setValue:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:6.0/256.0 green:57.0/256.0 blue:84.0/256.0 alpha:1.0]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
int borderSize = 3;
UIImageView *navBorder = [[UIImageView alloc] initWithFrame:CGRectMake(0,
41,
320,
borderSize)];
navBorder.image = [UIImage imageNamed:#"energy_line"];
navBorder.tag = 999;
[[UINavigationBar appearance] addSubview:navBorder];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
I have a method in my appdelegate that sets the window to my first viewController, when i call this method, my navBorder is removed from the navigationbar. I don't understand why this happens, there is no code that changes anything in my navigationbar in the viewcontroller.
- (void)rootView
{
[self.window setRootViewController:initialViewController];
}
I answered pretty much the same question here: https://stackoverflow.com/a/26414437/538491
But here is a summary:
Calling [[UINavigationBar appearance] returns an appearance proxy for the receiver class. The addSubview: method is not tagged as UI_APPEARANCE_SELECTOR. One major downside to UIAppearance's proxy approach is that it's difficult to know which selectors are compatible.
You should get a hold of the navigation bar and add the image there by calling this method: [self.navigationController.navigationBar addSubview:navBorder] or you should subclass UINavigationBar which gives you more flexibility.
I'm working on an app that's supposed to work on both iOS 6 and iOS 7, and have the same flat design for both.
I'm trying to customize my UISegmentedControl to have borders, corner radius and all, but I can't figure out how to do so. I've only mange to have a flat background so far.
Does anyone have any advice to have an iOS 6 UISegmentedControl look like an iOS 7 one ?
EDIT :
I would like to have
instead of
You can use below code:
// To set colour of text
NSDictionary *attributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[segmentedControl setTitleTextAttributes:highlightedAttributes forState:UIControlStateHighlighted];
// Change color of selected segment
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
UIColor *newTintColor = [UIColor colorWithRed: 255/255.0 green:100/255.0 blue:100/255.0 alpha:1.0];
segmentedControl.tintColor = newTintColor;
UIColor *newSelectedTintColor = [UIColor clearColor];
[[[segmentedControl subviews] objectAtIndex:0] setTintColor:newSelectedTintColor];
And for seting rounded corners you can use below code:
// Add rounded yellow corner to segmented controll view
[segmentedControl.layer setCornerRadius:4.0f];
[segmentedControl.layer setBorderColor:[UIColor colorWithRed:1.0 green:0.7 blue:0.14 alpha:1.0].CGColor];
[segmentedControl.layer setBorderWidth:1.5f];
[segmentedControl.layer setShadowColor:[UIColor blackColor].CGColor];
[segmentedControl.layer setShadowOpacity:0.8];
[segmentedControl.layer setShadowRadius:3.0];
[segmentedControl.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
You can take a look at an example here or take a custom control and change its images to fit your need.
Here's an example of how you can subclass UISegmentedControl:
#implementation CustomSegmentedControl
-(id)initWithItems:(NSArray *)items
{
self = [super initWithItems:items];
if (self) {
[self setDividerImage:[UIImage imageNamed:#"segmented-control-divider-none-selected"]
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[self setDividerImage:[UIImage imageNamed:#"segmented-control-divider-left-selected"]
forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[self setDividerImage:[UIImage imageNamed:#"segmented-control-divider-right-selected"]
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
// Set background images
UIImage *normalBackgroundImage = [UIImage imageNamed:#"segmented-control-normal"];
[self setBackgroundImage:normalBackgroundImage
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
UIImage *selectedBackgroundImage = [UIImage imageNamed:#"segmented-control-selected"];
[self setBackgroundImage:selectedBackgroundImage
forState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:selectedBackgroundImage
forState:UIControlStateHighlighted
barMetrics:UIBarMetricsDefault];
double dividerImageWidth = [self dividerImageForLeftSegmentState:UIControlStateHighlighted rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault].size.width;
[self setContentPositionAdjustment:UIOffsetMake(dividerImageWidth / 2, 0)
forSegmentType:UISegmentedControlSegmentLeft
barMetrics:UIBarMetricsDefault];
[self setContentPositionAdjustment:UIOffsetMake(- dividerImageWidth / 2, 0)
forSegmentType:UISegmentedControlSegmentRight
barMetrics:UIBarMetricsDefault];
return self;
}
I've finally used this submodule. It does the work :
https://github.com/pepibumur/PPiFlatSegmentedControl
I am trying to create an app in which the tab bar transparent (or which looks transparent). For this i'm using part of an image in the view. And set the remaining part as background for tab bar. The problem is the tab bar appears with a darker shade. I'm out of ideas now.
Below is the screen shot
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tabbar_bg.png"]];
self.tabBar.backgroundColor=[UIColor whiteColor];
[self.tabBar insertSubview:imgView atIndex:1];
// [self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"transp.png"]];
// [self.tabBar setSelectedImageTintColor:[UIColor clearColor]];
[[UITabBar appearance] setTintColor:[UIColor clearColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor clearColor]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"transp.png"]];
The above is the code that i've tried out in the viewDidLoad of my custom UITabBarController class. "tabbar_bg.png" is the image used as background for the tab bar and 'transp.png' is a transparent image used as the selectionIndicator image.
Thanks for the help.
Try
[self.tabBar setBackgroundImage:[UIImage new]];
This trick also works for UINavigationBar.
Have you tried creating a subclass of it?
#implementation TabBarInvisible
-(id)init
{
self = [super init];
if (self)
{
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.backgroundImage = nil;
}
return self;
}
-(void)drawRect:(CGRect)rect
{
}
#end