I am trying to add UIToolbar as titleview for navigationitem. toolbar has been sucessfully added on titleview. but seems like frame is not getting set properly.
above is output I am currently getting. I am not setting right/left bar button.
Thanks.
instead of assigning to titleview, add it as a subview
[navigationController.navigationBar addSubview:toolBar];
if it not works then do like following
create one view like this
UIView *yourView = [[UIView alloc] initWithFrame:navigationController.navigationBar.bounds];
yourView .backgroundColor = [UIColor yellowColor];
[yourView addSubView:toolBar];
ctrl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[navigationController.navigationBar addSubview:yourView];
Related
I want to create a subview with a NavigationBar and a TableView. In the Navigation Bar should be a button which can edit the tableView. The navigationBar and the TableView is shown in the subview but the barButtonItem not. Is there an error in my code, or is there a problem because it is a subview ?
UIView *tagView = [[UIView alloc] initWithFrame:CGRectMake(0, 325, screenSize.size.width, 200)];
tableView = [[UITableView alloc] initWithFrame:CGRectMake(-10, 40, screenSize.size.width, 150) style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
[tagView addSubview:tableView];
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, tagView.frame.size.width, 45)];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
[tagView addSubview:navigationBar];
[self.view addSubview:tagInstruction];
[self.view addSubview:tagView];
self.navigationItem refer to navigationController navigation item and you don't have any navigation controller, you have only custom NavigationBar and hence its not working.
For solving this problem you have to create your own UIButton and add in the subview of NavigationBar.
The navigationItem represents the view controller in a parent’s navigation bar, not in the navigationBar you are constructing here. Put the Button into your navigationBar.
If I need a clean navigationBar I always put my UIViewControllers in a UINavigationController. It does not hurt and you can add navigation functionality later. Then you can use self.navigationItem to add a UIBarButtonItem
Like Sven said, the self.navigationItem refers to the UINavigationItem for the UINavigationBar which belongs to the view controller's parent UINavigationController. If you want to set your button in the navigation bar you just alloc'd, try this:
UINavigationItem * navigationItem = [[UINavigationItem alloc] init];
navigationItem.leftBarButtonItem = self.editButtonItem;
[navigationBar setItems:#[navigationItem]];
I was wondering if it's possible to move my navigationController title closer to the top of the bar? Right now it looks like this.
I was thinking it would be
self.navigationItem.titleView = [[titleView alloc] initWithFrame:CGRectMake(100,2, 2,100)]];
But I guess titleView has to be another view?
Thanks for the help!
Give frame at the time of initialisation!
UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,32,32)];
[iv setBackgroundColor:[UIColor whiteColor]];
self.navigationItem.titleView = iv;
I have a 320x460 view with a number of buttons, depending on the button pressed, a 280x280 view pops up over the 320x460 view (similar to the behavior of the UIAlertView) using code like this:
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(20, 200, 280, 280)];
overlayView.backgroundColor = [UIColor whiteColor];
[overlayView autorelease];
[overlayView addSubview:label]; // label declared elsewhere
[overlayView addSubview:backgroundImage]; // backgroundImage declared elsewhere
//... Add a bunch of other controls
[label release];
[backgroundImage release];
//... Release a bunch of other controls
[self.view addSubview:overlayView];
Everything works fine displaying the overlayView and all its controls.
The question I have is, how do I get rid of the overlayView once it's displayed? I want to make it not only not visible but to remove it completely, since the user will be popping up the overlayView repeatedly during use.
You need access to overlayView to remove it, I'd suggest adding this to the create side:
overlayView.tag = 5; // Or some other non-zero number
Then later you can use it like this:
-(void)removeOverlayView
{
UIView *overlayView = [self.view viewWithTag:5];
[overlayView removeFromSuperview];
}
How can I change the line's color that separates the navigation bar and the view?
For instance flickr changed it to gray (http://www.geardiary.com/wp-content/uploads/2009/09/Screen-shot-2009-09-08-at-8.00.06-AM.png)
By default mine is always black...
Thanks in advance for your help,
nico
They used a custom bottom bar and not the Apple provided ones. I dont know your setup, but if you can make or draw your own custom view however you want (you can do this), and stick buttons on it (you can do this too), then you have a toolbar
#define TOOLBAR_HEIGHT 44
CGRect frame = CGRectMake(self.view.bounds.size.height - TOOLBAR_HEIGHT, 0.0, self.view.bounds.size.width, TOOLBAR_HEIGHT);
UIView *customBottomBar = [[UIView alloc] initWithFrame:frame];
[customBottomBar setBackgroundColor: [UIColor grayColor]];
UIButton *button = [[UIButton alloc] initWithFrame:<frame goes here>]
... <button setup>
[customBottomBar addSubview:button];
[button release];
...<more buttons>
...<more buttons>
[self.view addSubview:customBottomBar];
[customBottomBar release];
And to answer your question, you can add whatever you want to any view, so while the way I just suggest is the most customizable, you might just want to place a 1pixel high colored bar at the right spot (on top of the existing toolbar) by doing this:
CGRect frame = CGRectMake(self.view.bounds.size.height - TOOLBAR_HEIGHT, 0.0, self.view.bounds.size.width, 1);
UIView *customLine = [[UIView alloc] initWithFrame:frame];
[customLine setBackgroundColor: [UIColor grayColor]];
[self.view addSubview:customLine];
[customLine release];
what is the appropriate way to overlay two layers of an UIView for the iPhone? The underlaying view should be active until a button is pressed, then another UIView should cover
everything in a transparent way.
I found the Modal View Controllers, but they simply exchange UI-Views but don't overlay.
Thanks in advance.
Chris
You should use [existingView addSubview:newView]; to add a view to an existing view. the newView will appear on top of the existingView. So conceptually, you would create a button on existingView, connect it to an IBAction that calls a method like this:
CGRect newSize = CGRectMake(0.0f ,0.0f, 320.f, 400.0f);
UIView *newView = [[UIView alloc] initWithFrame:newSize];
[existingView addSubview:newView];
[newView release];
This will place a newView on top of the existingView.
following is a simple 3 line ARC-compatible with transparent overlay for UIView
_overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.view addSubview:_overlayView];