Add toolbar to the left side of an UISplittview - ipad

How can I add a toolbar on the left side of the splittview?
I have a navigationcontroller
and i already tried this:
UIToolbar *toolbar = [[UIToolbar alloc] init]; toolbar.barStyle =
UIBarStyleDefault;
[toolbar sizeToFit];
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc]
initWithTitle:#"back" style:UIBarButtonItemStyleBordered target:self
action:#selector(info_clicked:)];
[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
[self.navigationController.view addSubview:toolbar];
But it is noch working. It appears at the top and not at the bottom
MEMA

You don't have to create your own toolbar for a UINavigationController, just set toolbarHidden to NO to use its built-in one and add your UIBarButtonItem to it.

Related

Keyboard toolbar for multiple textFields

In my project, some viewControllers have multiple text fields,
I found how to add a toolbar above keyboard with a "Ok" button to hide keyboard when the button is tapped.
The code I am using is this below :
UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:_destField action:#selector(resignFirstResponder)];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 34)];
toolbar.items = [NSArray arrayWithObjects:flex, barButton, nil];
_destField.inputAccessoryView = toolbar;
How can I easily reuse this code in the same view controller?
The "target" makes this difficult, is there a way without creating a toolbar for each textField?
Thanks!
If this code is in a view controller then there is a simple solution. Change the barButton to something like this:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissKeyboard)];
Then add this method to the view controller:
- (void)dismissKeyboard {
[self.view endEditing:YES];
}
That will dismiss the keyboard no matter what view is showing it.
Now you can reuse that toolbar as the inputAccessoryView for any text field/view in the view controller.

Resizable Toolbar with bar button on UIDate Picker

I have used date picker at place of keypad.And UI bar Button With ok,cancel and Flexible space.
But It is not responsive when i change Portrait to LandScape mode.
Tool Bar:-
UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
toolbar.barStyle=UIBarStyleBlackTranslucent;
cancelBtn=[[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:nil];
flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
doneBtn = [[UIBarButtonItem alloc]initWithTitle:#"OK"style:UIBarButtonItemStyleDone target:self action:nil];
[toolbar setItems:[NSArray arrayWithObjects:cancelBtn,flexible,doneBtn,nil]];
[toolbar sizeToFit];
_txt_dob.inputAccessoryView=datePicker;
UIDate Picker:-
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[_txt_dob setInputView:datePicker];
[datePicker addSubview:toolbar];
LandScape Mode of Simulator.
Do not initialize your UIToolBar with frame. Instead use NSLayoutConstraint between your UIToolBar and its parent view to stretch it all the way. That way it will respond well to orientation changes.

How to add Bar Button in navigation bar without navigation controller.

I am new to iOS development.I have create a navigation bar in my iPad application view.I don't need navigation controller that's why i have added only navigation bar. Now i want to add button in that navigation bar.I tried a lot but no success. Is it possible to add only navigation bar with button ? If yes then suggest me some sample code.
"i don't have navigation controller or need it. i just want to add navigation bar in only one view."
Bellow is my code which i write for adding navigation bar in ViewDidLoad()
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 1026, 50)];
[navBar setTintColor:[UIColor blackColor]];
[navBar setDelegate:self];
[self.view addSubview:navBar];
Thanks in advance....
I used the Interface Builder to make a static tableView in a UITableViewController.
This UITableViewController is shown modally. Then I added a NavigationBar without the UINavigationController behind it as follows:
//Creating the plain Navigation Bar
UINavigationBar *headerView = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
//The UINavigationItem is neede as a "box" that holds the Buttons or other elements
UINavigationItem *buttonCarrier = [[UINavigationItem alloc]initWithTitle:#"Sign-In"];
//Creating some buttons:
UIBarButtonItem *barBackButton = [[UIBarButtonItem alloc] initWithTitle:#"Zurück" style:UIBarButtonItemStyleDone target:self action:#selector(signInBackPressed:)];
UIBarButtonItem *barDoneButton = [[UIBarButtonItem alloc] initWithTitle:#"Fertig" style:UIBarButtonItemStylePlain target:self action:#selector(signInDonePressed:)];
//Putting the Buttons on the Carrier
[buttonCarrier setLeftBarButtonItem:barBackButton];
[buttonCarrier setRightBarButtonItem:barDoneButton];
//The NavigationBar accepts those "Carrier" (UINavigationItem) inside an Array
NSArray *barItemArray = [[NSArray alloc]initWithObjects:buttonCarrier,nil];
// Attaching the Array to the NavigationBar
[headerView setItems:barItemArray];
// Adding the NavigationBar to the TableView
[self.tableView setTableHeaderView:headerView];
I hope this helps somebody!
UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:#"Edit" style:UIBarButtonItemStyleBordered target:self action:#selector(editButton)];
bi1.style = UIBarButtonItemStyleBordered;
bi1.tintColor = [UIColor colorWithWhite:0.305f alpha:0.0f];
self.navigationItem.rightBarButtonItem = bi1;
[bi1 release];
You can add buttons to navigation bar as follows:
UIBarButtonItem *btnSave = [[UIBarButtonItem alloc]
initWithTitle:#"Save"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(save_Clicked:)];
navBar.rightBarButtonItem = btnSave;
[btnSave release];
UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc]
initWithTitle:#"Cancel"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(cancel_Clicked:)];
navBar.leftBarButtonItem = btnCancel;
[btnCancel release];

iOS - UIToolBar as inputAccessoryView for UITextView

I've added a UIToolBar with a UIBarButtonItem as inputAccessoryView for a UITextView. It works fine but the UIBarButtonItem is touchable outside it's frame, perhaps 50 pixels outside to the right. It's no big deal but it annoys me. Anyone know why?
This is my code (ARC):
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.barStyle = UIBarStyleBlack;
toolBar.translucent = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneWriting:)];
[toolBar setItems:[NSArray arrayWithObjects:doneButton, nil]];
self.messageTextView.inputAccessoryView = toolBar;
In iOS 6 it seems to behave as expected.
Nice tip: If you want the button to appear on the right instead of the left, use one of these:
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
Then initialise the toolbar with:
[toolBar setItems:[NSArray arrayWithObjects:flexibleSpace, doneButton, nil]];
The toolbar seems to expand the active area of the buttons beyond their bounds if there are no other nearby buttons in the toolbar. Apple engineers must think it is better to try to guess where the user intended to press rather than not react at all.
I hope it helps you...
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
[keyboardDoneButtonView sizeToFit];
UIBarButtonItem* PrevButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:105 target:nil action:nil]; //<
UIBarButtonItem* NextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 target:nil action:nil]; //>
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(doneClicked:)];
UIBarButtonItem* flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *fake = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:nil action:nil] ;
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects: PrevButton,fake, NextButton,fake,flexSpace,fake,doneButton,nil] animated:YES];
Use Fake Item to get exact pinch location on Button...

How to add buttons to the top bar of a detail view from a UITableView

When an item from a UITableView is selected, a detail view is loaded which has a banner bar at the top with a back button on it to navigate back to the table.
How do I add other buttons to that banner bar?
As Andrew said, you can add custom views to the navigation bar. For example, if you are looking to add multiple buttons to the right side of the navigation bar, you can do something like this:
// right side of nav bar
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 106, 44)];
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];
UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
target:self
action:#selector(deleteAction:)];
deleteButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:deleteButton];
[deleteButton release];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancelAction:)];
cancelButton.style = UIBarButtonItemStylePlain;
[buttons addObject:cancelButton];
[cancelButton release];
[toolbar setItems:buttons animated:NO];
toolbar.barStyle = -1;
[buttons release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[toolbar release];
Make sure to adjust the width (106 above) if you need more or wider buttons, and then provide methods for the selectors (deleteAction: and cancelAction: above).
From your description, it sounds like you have a UINavigationController correctly set up. That "banner bar" you are describing is properly called a navigation bar.
From within the detail view, you can use:
UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:"HiMom" style:UIBarButtonItemStylePlain target:self action:#selector(onHiMom:)] autorelease];
self.navigationItem.rightBarButtonItem = button;
You can also add custom views (instead of a button) plus a few other settings. I suggest poking around the documentation for UINavigationItem, UINavigationBar, and UIBarButtonItem for ideas.

Resources