I have seen it done on some apps, where the navigation bar is actually smaller than the default 44px, and there is a UIView (which has functionality) above the nav bar...
I want more than a custom background image, which I did manage to figure out how to do, but I dont know where to start getting something like this done.
Any help is greatly appreciated :)
Mark
I found a sort of way to do this:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 32.0f)];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
UIImageView *back = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"logo.png"]];
[back setFrame: CGRectMake(0, 0, 320, 20)];
[tempView addSubview: back];
[[self view] addSubview: tempView];
[[self view] addSubview: navBar];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle: #"Controls"];
[navBar pushNavigationItem:navItem animated:NO];
which seems to do the trick, although I cannot seem to figure out how to get this 'into' the navigationController so that back buttons work, at the moment I have to manually insert a leftBarButtonItem into the navItem, the back button never seems to show...
Yes you can,
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 32.0f)];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
navBar.navigationBar.layer.zPosition =-1;
self.view insertSubview:navBar atIndex:[[self.view subviews] count]];
[self.view insertSubview:tempView atIndex:[[self.view subviews] count]];
Related
I want to put Custom image on my UINavigationBar,
When i tried this two code snippets,
[self.navigationItem setTitleView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"logo.png"]]];
And
UIButton *logoView = [[UIButton alloc] initWithFrame:CGRectMake(0,0,70,30)];
[logoView setBackgroundImage:[UIImage imageNamed:#"logo.png"] forState:UIControlStateNormal];
[logoView setUserInteractionEnabled:NO];
self.navigationItem.titleView = logoView;
image which i can see on my Device is getting blur or it is getting streched.
I made image with Resolution of 180*40(Width*Height)
I want to know the exact size of Image. what, it would be ?
Thanks in advance.
use this
UIImageView *navigationImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 98, 34)];
navigationImage.image=[UIImage imageNamed:#"topNav-logo.png"];
UIImageView *workaroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 98, 34)];
[workaroundImageView addSubview:navigationImage];
self.navigationItem.titleView=workaroundImageView;
hope this helps.
Create Image with size (320 x 44) and set as a Title like bellow..
self.navigationItem.titleView = yourImageView;
See whole example like bellow...
- (void)viewDidLoad{
UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"logo.png"]];
self.navigationItem.titleView = imgView;
[imgView release];
}
You need to first initialize the titleView. and then set it the imageView as a subView:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"logo.png"]];
self.navigationItem.titleView = [[UIView alloc] initWithFrame:imageView.bounds];
[self.navigationItem.titleView addSubview:imageView];
I am trying to add a UILabel programmatically into my UIToolBar but it dose not seem to be appearing. This is what I am doing with my code.
- (void) viewWillAppear:(BOOL)animated
{
// Create custom toolbar at top of screen under navigation controller
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
matchingSeriesInfoToolBar = [UIToolbar new];
[matchingSeriesInfoToolBar sizeToFit];
CGFloat toolbarHeight = 30;
CGRect mainViewBounds = [[UIScreen mainScreen] applicationFrame];
[matchingSeriesInfoToolBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 0, CGRectGetWidth(mainViewBounds), toolbarHeight)];
matchingSeriesInfoToolBar.tintColor = [UIColor darkGrayColor];
[self.view addSubview:matchingSeriesInfoToolBar];
// Create size of uitableview (to fit toolbar.
[matchingSeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
[self.view addSubview:matchingSeriesTableView];
// Ad UILabel to the toolbar
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:manufSelectionLabel];
matchingSeriesInfoToolBar.items = [NSArray arrayWithObject:textFieldItem];
manufSelectionLabel.text = #"Hello World!";
[super viewWillAppear:animated];
}
So pretty much I have created a custom toolbar which I have changed the usual location from the bottom of the screen, to appear under the UINavigationController, this is also added to the view like this so it animated properly in the view transitions..
After which I create the size of the tableview so that it appears after the custom toolbar..
then from there I am trying to add a UILabel to the toolbar.. but for some reason its not working out.
Any help would be greatly appreciated.
You must actually create the label somewhere. This code works just fine.
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:toolbar];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
label.backgroundColor = [UIColor clearColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
toolbar.items = [NSArray arrayWithObject:item];
label.text = #"Hello World";
In the code you posted you don't ever make a UILabel. Your comment says Ad UILabel to the toolbar but you then proceed to make a UIBarButtonItem with a custom view manufSectionLabel.
Where is the code which creates manufSectionLabel?
PS This line does nothing :
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
because at that point matchingSeriesInfoToolbar is nil - you haven't made it yet!
When this Action is executed it displays totally black view screen with toolbar
- (void)displayviewsAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
self.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:toolbar];
UIView *viewController = [[UIView alloc] init];
UIView *secondController = [[UIView alloc] init];
[self.view insertSubview:viewController atIndex:1];
[self.view insertSubview:secondController atIndex:2];
NSLog(#"%d", [[self.view subviews] indexOfObject:viewController]); // Is 1
NSLog(#"%d", [[self.view subviews] indexOfObject:secondController]); // Is 2
[self.view bringSubviewToFront:viewController];
NSLog(#"%d", [[self.view subviews] indexOfObject:viewController]);
[self.view sendSubviewToBack:viewController];
NSLog(#"%d", [[self.view subviews] indexOfObject:viewController]);
[self.view bringSubviewToFront:secondController];
NSLog(#"%d", [[self.view subviews] indexOfObject:secondController]);
SecondViewController * secondController = [[[SecondViewController alloc] init]autorelease];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:secondController.view];
[self.view addSubview:toolbar];
}
Any ideas why the view is appearing as totally black with toolbar.
The default background color of views is nil, which is a transparent background.
If you have nothing in any of the views and set no background color for any of them, the default background of the window or the device will show through. I didn't see it in the documentation, but I am assuming it is black.
Also, you have defined UIView pointers, but named them with the word "controller". This can contribute to mistakes since a UIViewController is an entirely different object. The UIViewController contains a UIView and interacts with it, but it is not a UIView, nor does it inherit from one.
I added a UISearchBar and UISearchDisplayController with a UINavigationController. Because we needed a few buttons in the navigationBar, I created a custom view that contains a few buttons, and put that as the rightBarButtonItem. I notice when I click on the search bar, the keyboard pops up from the bottom, and also moves the UINavigationController's navigationBar off the screen. So now I cannot see what I enter in my UISearchBar. Is there a way to get around this? I've seen other apps that it looks like they use a UINavigationBar + multiple buttons on the LHS or RHS of the navigationBar, so I'm assuming this is possible. Thanks.
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
UIImage *house = [UIImage imageNamed:#"icon_house.png"];
[homeButton setImage:house forState:UIControlStateNormal];
[homeButton addTarget:self action:#selector(homePressed:) forControlEvents:UIControlEventTouchUpInside];
UIButton *filterButton = [[UIButton alloc] initWithFrame:CGRectMake(49, 0, 44, 44)];
[filterButton setTitle:#"Filter" forState:UIControlStateNormal];
[filterButton addTarget:self action:#selector(FilterButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.SearchEntry = [[[UISearchBar alloc] initWithFrame:CGRectMake(98, 0, 150, 44)] autorelease];
self.SearchEntry.delegate = self;
UISearchDisplayController *searchDisplayCtlr = [[UISearchDisplayController alloc] initWithSearchBar:_searchEntry contentsController:self];
searchDisplayCtlr.searchResultsDataSource = self;
searchDisplayCtlr.searchResultsDelegate = self;
searchDisplayCtlr.delegate = self;
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 248, 44)];
[containerView addSubview:homeButton];
[containerView addSubview:filterButton];
[containerView addSubview:_searchEntry];
Try to adjust the contentSize of the UIScrollView. Also please take care of the Hierarchy of the controls you have taken. Dont keep UINavigationBar and UISearchView in ScrollView, then it will not move and remains fixed in their position
It's easy to change background color of a searchbar.But, I have no idea how to change its background image.There is no direct method.
I need help...............
I appreciate any given idea...
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIImageView* iview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"test.png"]];
iview.frame = CGRectMake(0, 0, 320, 44);
[bar insertSubview:iview atIndex:1];
[iview release];
[self.view addSubview:bar];
[bar release];
searchBar.backgroundImage = [UIImage imageNamed:#"searchBackground"];
if you want to use an image as the background of the search bar, you can use,
searchBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"search_bg.png"]];