I want to insert an UIView between Navigation Bar and UIView (Underneath NavigationBar) to show network connectivity status.
Also View underneath Nav Bar should go downward to make a space for indicatorView.
My code:
indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 35)];
[self.view addSubview:indicatorView];
self.view.frame = CGRectMake(0, 35, VIEW_WIDTH, VIEW_HEIGHT - 35);
This inserts a view but whole window shift upwards and create a space at bottom of View. What's wrong?
Related
I set a default background image for UISearchBar:
[[UISearchBar appearance]setSearchFieldBackgroundImage:[UIImage imageNamed:#"search_field"] forState:UIControlStateNormal];
I then have a UISearchBar set to the nav bar's titleView.
UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 35)];
lsearchBar = [[TestSearchBar alloc]initWithFrame:searchView.frame];
[searchView setBackgroundColor:[UIColor clearColor]];
[searchView addSubview:lsearchBar];
But the result looks horrible with a crushed graphic for my search bar:
If it try to embed it without using UIView directly, like this:
lessonsSearchBar = [[TestSearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 35)];
self.navigationItem.titleView = lessonsSearchBar;
it looks better, but when I push segue to the next view controller, or do pop back with animation it tries to animate it and looks horrible with this gray bar around it:
I do try it inside UIView because I also want to set a custom size to my UISearchBar and realign it a bit to the left side of the screen, which for some reason is not allowed when I set my search bar directly to navitationItem.titleView. I'm not sure exactly how to achieve this without crashing my image (which I set with setSearchFieldBackgroundImage) or without those glitches with animation. Can you please help?
I have the code below in my viewcontroller.m:
panoView_ = [[GMSPanoramaView alloc] initWithFrame:CGRectMake(0, 0, 10, 25)];
self.view = panoView_;
[panoView_ moveNearCoordinate:CLLocationCoordinate2DMake(-33.732, 150.312)];
I want to create a little space at the bottom of the view to place a button in the storyboard but this isn't working as the map (street view) takes up the entire screen. Any advice?
If you want the button to appear below the map then use 2 views.one view (panoViewContainer) contains a panoView and second view (mainView - which is self.view) contains panoViewContainer and a button below panoViewContainer.
// Place panoViewContainer in mainView by keeping space for button at bottom,
self.panoViewContainer.frame = CGRectMake(0, 0, width, (height - spaceForButton));
[self.mainView addSubview:self.panoViewContainer];
self.panoViewContainer = panoView_;
// Place a button in mainView, below panoViewContainer.
[self.mainView addSubview:button];
I have an UImage that I need half on the navigation bar and half on the main screen. I have added a Navigation Controller on my project so now I have a nav bar on all screens. I need a square image to go half on the navigation controller and half on the main screen.
In XCODE I have successfully put an UImageView over the nav bar and the main screen but when i put an image on it i only appears in the part thats over the main screen and not over the navigation bar. I don't want to split the image so I can use Navigationbar.image control - is there another way ?
Instead of adding it to viewController, add it to window.
UIView *view =[[UIView alloc] initWithFrame:CGRectMake(40, 30,240,60)];
view.backgroundColor =[UIColor greenColor];
[[[UIApplication sharedApplication] delegate].window addSubview:view];
As you might have noticed the UINavigationBar appears on top of everything you have within your UIViewController's view.
One way of overcoming this is by adding your UIImageView to the keyWindow like so:
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imageView.image = [UIImage imageNamed:#"myImage"];
[[UIApplication sharedApplication].keyWindow addSubview:imageView];
So this is the code for my mapView:
self.mapView = [[MKMapView alloc] init];
self.mapView.frame = CGRectMake(0, 70 , self.view.bounds.size.width,
self.view.bounds.size.height);
When I push to this view controller from one viewcontroller it looks just fine. The navigation bar and map view are all in the correct spot; however, when I tried to create a button that go directly to the map Viewcontroller from ANOTHER viewController everything changed.
The map view has shrunk and the navigation bar is missing now..? Here's the new button from the other ViewController:
UIImage* image4 = [UIImage imageNamed:#"Near_me_carousel.png"];
_mapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 18, 26, 26)];
[_mapButton setBackgroundImage:image4 forState:UIControlStateNormal];
[_mapButton addTarget:self action:#selector(MapButton)
forControlEvents:UIControlEventTouchUpInside];
[_mapButton setShowsTouchWhenHighlighted:YES];
[self.view addSubview:_mapButton];
Here's the method:
-(void) MapButton {
MapViewController *mapView = [[MapViewController alloc] init];
[self.navigationController presentViewController:mapView animated:YES completion:NULL];
}
I'm so confused as to why this is happening! Any ideas?
I don't know if this is really your problem, but here's a shot:
Inside your button method, you are calling your MapViewController modally. If the viewController itself does not have a UINavigationBar, of course it will not be displayed.
When you have a push transition, through a UINavigationController, a navigationBar is automatically added above of your view.
And here's the tricky part: when presented as a push transition, the 0 y value of the view's frame is the point just below the navigationBar. I. e., the navigationBar does not belong to your view.
And when presented through a modal transition (presentViewController:), the 0 y value is the top/left point of the window, even if you add a NavigationBar yourself.
Ilustrating:
The origin of it will be here if presented as a modal:
And here if presented if a push in a navigation stack:
Conclusion:
So, in your case, the y-value 70 in this code
self.mapView.frame = CGRectMake(0, 70 , self.view.bounds.size.width,
self.view.bounds.size.height);
will be different according to the transition style. In a modal, it will look like it's displaced 44 points to the top (size of the navigation bar)
I have a subview in my navigation bar. I try to add it by this way:
UIView *customView =
[[UIView alloc] initWithFrame:
CGRectMake(0, 0, image.size.width + label.frame.size.width, 44)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[customView addSubview:imageView];
[customView addSubview:label];
[self.navigationController.navigationBar addSubview:customView];
However, when I try to push the navigation bar, the customView stays in the place, not animating following the sliding navigation bar. How can I achieve the animated subview? Is it even possible? Thanks!
you should not add subview in that way
you have tospecify your view location in the left , right or title view
self.navigationItem.titleView = YOURVIEW;
or choose another location left or right items in this way the the title view will added to the current view if you want to remove it just set it to nil in the place you want and reload it subviews again,
self.navigationItem.titleView = nil;
As you are using
[self.navigationController.navigationBar addSubview:customView];
that means the navigation bar you have create is in App delegate and is common for all the viewControllers in your project,that is why once you add a view on to it you see it on every view you have. Remove your sub-view in
-(void)viewWillDisappear:(BOOL)animated{
[Your subview remove fromSuperView];
[super viewWillDisappear:YES];
}
and add that subview in
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController.navigationBar addSubview:Your subview];
[super viewWillAppear:YES];
}
this will add the subview in that particular view only and remove it as soon as that view is popped or pushed.The code given is not correct to the syntax please give a check on that.