I am trying to create a view that looks like the following:
I know it's a UISplitView, however my issue is that on creating the UIToolBar that is below the UITableView to the left and also on how to create the icons on top of the detail view (the one with the trash can logo, reply, and new message). How do I do this?
If you look at the DetailView.xib for a UISplitView project in Interface Builder you can drag UIBarButtonItems onto the toolbar contained in it.
To get a toolbar in the popover controller you can just use the toobar that comes with a UINavigationController. The code below should give you an idea of how to do this. Add this code to RootViewController.
- (void)viewDidLoad
{
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
//setup toolbar
self.navigationController.toolbarHidden = NO;
UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:#selector(refresh:)];
[self setToolbarItems:[NSArray arrayWithObjects:refreshItem, nil]];
[refreshItem release];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60.0, 10.0, 200.0, 21.0)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = #"This is a label on the toolbar";
[self.navigationController.toolbar addSubview:label];
[label release];
}
Related
I am attempting to set a label into a subclassed UIToolBar. I am first creating the label, then converting it to a UIBarButtonItem and setting them to the toolbar, but the toolbar just appears blank.
here is my code in my init method of my subclassed toolbar
NSMutableArray *items = [[NSMutableArray alloc] init];
// prep the total label
_totalLabel = [[UILabel alloc] init];
_totalLabel.font = [_totalLabel.font fontWithSize:15];
_totalLabel.textColor = [UIColor whiteColor];
_totalLabel.text = NSLocalizedString(#"TOTAL", nil);
_totalLabel.frame = CGRectMake(0, 0, 100, 44);
_totalLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
_totalLabel.layer.borderWidth = 2;
_totalLabel.layer.borderColor = [UIColor greenColor].CGColor;
_totalLabel.backgroundColor = [UIColor clearColor];
UIBarButtonItem *spacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:spacer2];
UIBarButtonItem *total = [[UIBarButtonItem alloc] initWithCustomView:_totalLabel];
[items addObject:total];
[self setItems:items];
any idea whats wrong?
Where are you calling this code from? If you have it in initWithFrame: or initWithCoder: it will not work.
Try this:
- (void)layoutSubviews {
[super layoutSubviews];
if(self.items.count == 0) {
//Your code here
}
}
That will get it working. The question is though should you be doing this in layoutSubviews? Probably not. You could also put a setup method on your UIToolbar and call that at a later point in your application.
This is not a uitoolbar. this is a navigation bar so please remove navigationbar and add toolbar . Try this type .
As you see my image, the Navigation title is under the two buttons.
The two left/right buttons are added subviews to navigation Bar.
How can i set the navigation title width?? Eventhough it looks like ...
My code is as follow:
self.navigationItem.titleView.frame=CGRectMake(0, 0, 20, 40);
[[self navigationItem]setTitleView:bigLabel];
If your UILable is too long you can set navigation bar Title like this way iniphone` but in ipad you can use same logic :-
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[label setBackgroundColor:[UIColor clearColor]];
[label setNumberOfLines:0];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:12]];
NSString *str =#"1234567890 1234567890 1234567890 1234567890 1234567890 123456";
[label setText:str];
self.navigationItem.titleView = label;
}
Hope its helps you .. :)
Use Custom UIView with one button one switch and one title. Either make it by Xib or make it by code. And Hide default navigation bar.
Try to change the x position of the added subviews.
Make that something like this:
Yoursubview.frame=CGRectMake(self.view.size.width-Yoursubview.frame.size.width,0,Yoursubview.frame.size.width,Yoursubview.frame.size.height);
I created a nav bar and a label programmatically in my view controller. Now I want to add a "done" button but cant seem to find a way without using IB....is there any way to do that?
Here is my view controller's viewDidLoad:
//Adding navBar programmatically
CGFloat width = self.view.frame.size.width;
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0,width,52)];
navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:navBar];
//Adding label to navBar programmatically
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,2,width-20,14)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.text = #"TITLE";
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:22];
label.shadowOffset = CGSizeMake(1,1);
label.textColor = [UIColor whiteColor];
label.textAlignment = UITextAlignmentCenter;
[navBar addSubview:label];
//Adding back button to navBar programmatically
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(dismissView:)];
self.navigationItem.leftBarButtonItem = rightButton;
Last part obviously doesnt work...
Thanks for any help!
Why are you not using a UIToolBar instead?
To add buttons to a UINavigationBar, you need to create a UINavigationItem. If you're using UINavigationBar as part of UINavigationController (as is the common case), this is done automatically, as a standalone view, you have to do this yourself.
UINavigationItem *item = [[[UINavigationItem alloc] initWithTitle:#""] autorelease];
item.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(dismissView:)] autorelease];
[navBar setItems:[NSArray arrayWithObject:item] animated:NO];
The navigationItem is only used when you push a viewcontroller in a navigationcontroller
in your case you need to use
-pushNavigationItem:animated:
on the UINavigationBar
Check the docs for more details:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UINavigationBar_Class/Reference/UINavigationBar.html
Hello Everyone
I am writing a simple code in ViewDidLoad, and class is child of UITableViewController, like below but buttons are not visible, while title is visible,
Another thing that I am clicking a button which in ViewDidLoad method ViewController.m, and which is call a method, code of that method is as below
//Code of button target method
-(void)statusMethod {
NSLog(#"statusMethod");
Status *ob=[[Status alloc]init];
[self presentModalViewController:ob animated:YES];
}
//Code of ViewDidLoad of Status.m
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, width, 43)];
navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:navBar];
[navBar release];
UIBarButtonItem *home = [[UIBarButtonItem alloc] initWithTitle:#"HOME" style:UIBarButtonItemStylePlain target:self action:#selector(homeMethod)];
self.navigationItem.rightBarButtonItem = home;
UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithTitle:#"Add" style:UIBarButtonSystemItemAdd target:self action:#selector(addMethod)];
self.navigationItem.leftBarButtonItem = add;
UILabel *label = [[UILabel alloc] initWithFrame:
CGRectMake(10,10,width-20,25)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.text = #"Status";
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:25];
label.textAlignment = UITextAlignmentCenter;
[navBar addSubview:label];
[label release];
Any Idea, what is problem in code?
I you don't understand, then u can ask me again,
I will praise, if I will get solution of my problem
It seems like self.navigationItem is only looked at by the UINavigationController (controller, not bar). The bar itself isn’t going to check that.
So you should either
1) Use a real UINavigationController which comes with its own navigationBar and will handle the navigationItems for you. The self.navigationItem code above will work in that case. (you should consider self.navigationItem.title = #"Status";)
If your UITableViewController is going to be pushing stuff on and off the navigation stack, this is the path you should take in any case.
2) Use the UINavigationBar’s own navigation item. Except it doesn’t seem to come with a navigation item, so you have to add your own:
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:#"Status"];
[navBar setItems:[NSArray arrayWithObject:navItem]];
[navItem release];
and then set the left and right buttons as
[navBar topItem].leftBarButtonItem = add;
[add release];
[navBar topItem].rightBarButtonItem = home;
[home release];
Dealing with UINavigationController/UINavigationBar/UINavigationItem can be confusing, but luckily Apple has a decent explanation of how all these things work together at the top of its UINavigationController documentation.
I want to add a custom UIImageView to UISearchDisplayController's table view background and set table view's background color to clearColor. Tried a few different approach but couldn't find the right solution. Any idea how to approach this?
Note: I don't want to add to searchDisplayController's searchResultsTableView's view hierarchy, but rather overlay another sibling view below it)
You can set the background image in a similar way you would for your main table, only set it in the searchDisplayControllerDidBeginSearch delegate method. For instance:-
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[controller.searchResultsTableView setDelegate:self];
UIImageView *anImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"gradientBackground.png"]];
controller.searchResultsTableView.backgroundView = anImage;
[anImage release];
controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
controller.searchResultsTableView.backgroundColor = [UIColor clearColor]; }
You can also do this wherever you instantiate your UISearchDisplayController. In my app I was doing this in my UITableView viewDidLoad method and was matching the styles between the two tables:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.separatorColor = [UIColor blackColor];
self.tableView.backgroundColor = [UIColor grayColor];
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
searchController.searchResultsTableView.separatorColor = self.tableView.separatorColor;
searchController.searchResultsTableView.backgroundColor = self.tableView.backgroundColor;
searchController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
}