White line under UINavigationBar in IOS 7 - ios

I have a UITableViewController with a UISearchDisplayController and UISearchBar. I'm seeing a white line under the navbar when I present the view in a UITabBarController. When I present the view modally in a UINavigationController, the line is either gray or black (I can't tell) and it looks perfectly normal. Any ideas?

I had the same problem, couldn't figure out from where it did came from (it was present everywhere and it was NOT the shadowImage), ended up with the following fix (in my UINavigationController subclass)
// Fixes strange line under NavigationBar
{
UIView * view = [[UIView alloc] init];
view.backgroundColor = self.navigationBar.barTintColor;
CGRect rect = view.frame;
rect.origin.x = 0.f;
rect.origin.y = self.navigationBar.frame.size.height;
rect.size.width = self.navigationBar.frame.size.width;
rect.size.height = 1.f;
view.frame = rect;
[self.navigationBar addSubview:view];
}

I had the same problem too, after trying with a lot of methods,I find this way solved my problem
[[UISearchBar appearance] setBackgroundColor:[UIColor yourColor]];
write it in your viewDidLoad.

The white line is probably the shadowImage of navigation bar.
Try setting it as:
self.navigationController.navigationBar.shadowImage = [UIImage new];

Try setting the clipsToBounds property on the UISearchBar to YES.

Use following line of the code :
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
[overlayView setBackgroundColor:[UIColor whiteColor]]; // set color accordingly
[navBar addSubview:overlayView]; // navBar is your UINavigationBar instance
[overlayView release];
here is my posted Answer :
Horizontal Separator NavBar IOS 7
How to remove UINavigatonItem's border line

Swift version of Divya's answers
let hideLineView = UIView(frame: CGRect(x: 0, y: navigationController!.navigationBar.frame.size.height, width: view.frame.size.width, height: 1))
hideLineView.backgroundColor = UIColor.white
navigationController!.navigationBar.addSubview(hideLineView)

Related

when home button pressed view origin changed?

I have this code in viewDidLoad:
[self.navigationController setNavigationBarHidden:YES];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.view.backgroundColor = [UIColor whiteColor];
//we need to add white background behind the status bar
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
UIView* statusBarWhiteBackGround = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, statusBarHeight)];
[statusBarWhiteBackGround setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:statusBarWhiteBackGround];
UIView * redBackGroundColor = [[UIView alloc] init];
[redBackGroundColor setBackgroundColor:[UIColor redColor]];
redBackGroundColor.frame =CGRectMake(0,statusBarHeight , self.view.frame.size.width, self.view.frame.size.height-statusBarHeight);
[self.view addSubview:redBackGroundColor];
statusWhiteBackGround view is used to change the color of the status bar.
here is the result of the above code:
but when the app enter background and then back to foreground, the redBackGroundColor view change it's orging.y as you can see in the bellow picture:
what's the problem ?thanks
Create a UIView programatically on method
-(void)viewDidLayoutSubviews{
screen=[[UIScreen mainScreen] bounds];
//Simple view
self.customView = [[CustomAlertOKView alloc]initWithFrame:CGRectMake(0, 20, screen.size.width, screen.size.height)];
[self.view addSubView:customView];
}
or
Create a view using storyboard and set the x as 0, y value as 20,width and height based on the screen size
#IBOutlet UIView *customView;
set the outlet in the storyboard,
Then set the background color of the custom view to redcolor and main view to white color
self.view.backgroundColor = [UIColor whiteColor];
customView.backgroundColor = [UIColor redColor];

How to set Shadow for a UISegmentedControl?

I have this method applyShadow which applies the shadow , and this works fine for UIViews and for UINavigationBar,but When I try it to UISegmentedControl, it doesnt work.
-(void) applyShadow
{
[self.layer setShadowOffset:CGSizeMake(0, 1.0)];
[self.layer setShadowRadius:1.0];
[self.layer setShadowOpacity:.15];
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
}
I tried this but didn't work:
[self.tabSegment applyShadow];
It is not the best answer but try adding UISegmentedControl to a UIView as a subview. But be careful about setting the frames of each other the same.
Adding a UIView behind the Segment bar didnt work out for me, so I did find a quick solution to it, I added a UIView below the segment bar and applies shadow to it.If anyone come up with a better solution,I always welcome them.
self.shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
self.shadowView.backgroundColor = [UIColor whiteColor];
[self.shadowView applyShadow];
[self.view addSubview:self.shadowView];

Add UISlider To UINavigationBar

Trying to add a UISlider to UINavigationBar. I have it to where the slider shows, but when trying to change the value, it will not move. Here is the code in viewWillAppear. Note that this is on a child view and not the main parent view.
UIView *viewofslider = [[UIView alloc] initWithFrame:CGRectMake(160, 10, 40, 30)];
UISlider *theslider = [[UISlider alloc] init];
[theslider addTarget:self action:#selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[theslider setBackgroundColor:[UIColor clearColor]];
theslider.minimumValue = 50.0;
theslider.maximumValue = 150.0;
theslider.continuous = YES;
theslider.value = 100.0;
[viewofslider addSubview:theslider];
[self.navigationController.navigationBar addSubview:viewofslider];
To answer your specific question, I think the width of viewofslider is too narrow at 40.0, so the touch is not being picked up by the UISlider.
If you change the width of viewofslider to 100.0 you should be able to interact with it.
However, I agree with rmaddy's comment that you should simply add the slider to the navigation bar, there's no obvious need for the UIView.
Try to add it to titleView of view controller's navigation item in viewWillAppear:
UISlider *theslider = [[UISlider alloc] init];
...
self.navigationItem.titleView = theslider;

UIToolbar tintColor and barTintColor issues

I have code like so:
UIView *colorView = [[UIView alloc] init];
colorView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 64.0);
colorView.backgroundColor = [UIColor blackColor];
//colorView.tintColor = [UIColor blackColor];
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0);
self.view addSubview:colorView];
[self.view addSubview:toolbar];
Why does the toolbar subview have a different color then my view? The view appears black and the toolbar appears light gray? Is there a blur or something causing this?
Behavior from some of the properties of UINavigationBar has changed from iOS 7. I have already explained this thing in my Answer.
Take a look at the Bar style for iOS 6 and iOS 7 :
You can note two points here :
You can change the Bar style to translucent dark instead of translucent light (default).
You can change the translucent property to NO from YES (default).
Try this code, it will help you,
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0);
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.tintColor = [UIColor blackColor];
toolbar.alpha = 0.0;
Change the tintColor and alpha based on your requirement.

Placing a fixed position toolbar in a Split View Controller's root view

I am having a problem placing a tool bar in the root view controller for a split view IPad app. I tried reducing the table view size and placing a toolbar under it, but the frame adjustment doesn’t take and the toolbar ends up scrolling with the table and not staying at the bottom of the screen like I want.
Here is the code that I am using in viewDidLoad:
self.tableView.frame = CGRectMake(0, searchBar.bounds.size.height, 320, 655 - searchBar.bounds.size.height);
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlack;
toolbar.frame = CGRectMake(0, 655, 320, 50);
[self.view addSubview:toolbar];
Thanks.
Found a nice solution to this problem, here is the code:
[super viewWillAppear: animated];
toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleBlack;
toolbar.frame = CGRectMake(0, 0, 320, 49);
[toolbar sizeToFit];
CGFloat toolbarHeight = 49;
CGRect rootViewBounds = self.parentViewController.view.bounds;
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);
[toolbar setFrame:rectArea];
[self.navigationController.view addSubview:toolbar];
[[self tableView] reloadData];

Resources