UIBarButton Deprecated in IOS 8.0 - ios

After changing the deployment target from 7.1 to 8.2, I just got a warning telling me that UIBarButton is deprecated.
Here is the code that I use:
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(nextButton)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], nil];
self.numberOfGuestsTextField.inputAccessoryView = numberToolbar;
Is there anything that I can use instead of UIBarButtonItem

UIBarButtonItem is not deprecated - UIBarButtonItemStyleBordered is. Just use UIBarButtonItemStylePlain or UIBarButtonItemStyleDone instead.
As of iOS 7, the style of bar buttons has changed to a more flat form. That's why UIBarButtonItemStyleBordered is no longer available - it just looks like a UIBarButtonItemStylePlain button. With UIBarButtonItemStyleDone, the text will be bold instead of regular.

Related

UiNavigationbar buttons not responding after upgrade to iOS 11

After upgrading to iOS 11 and to XCode9 my App's NavigationBar buttons (left and right) are not responding. It is working well in previous version but not in iOS 11. can anybody help me or have faced the same issue. My App is in Objective c language.
**//here is code for leftbarbutton**
UIImage *backSVG = [UIImage imageWithSVGNamed:#"backarrow32" targetSize:CGSizeMake(25, 25) fillColor:[UIColor whiteColor]];
UIBarButtonItem *notifyButton = [[UIBarButtonItem alloc] initWithImage:backSVG style:UIBarButtonItemStylePlain target:self action:#selector(handleBackButton)];
[notifyButton setStyle:UIBarButtonItemStylePlain];
self.navigationItem.leftBarButtonItem = notifyButton;
**//Rightbar buttons are**
UIBarButtonItem *rightbar1 = [[UIBarButtonItem alloc] initWithImage:
[UIImage imageWithSVGNamed:#"rightbar1" targetSize:CGSizeMake(21, 21)
fillColor:[UIColor whiteColor]] style:UIBarButtonItemStylePlain target:self
action:nil];
[rightbar1 setAction:#selector(handlerightbar1Action)];
UIBarButtonItem *rightbar2 = [[UIBarButtonItem alloc] initWithImage:
[UIImage imageWithSVGNamed:#"rightbar2" targetSize:CGSizeMake(21, 21)
fillColor:[UIColor whiteColor]] style:UIBarButtonItemStylePlain
target:self action:nil];
[rightbar2 setAction:#selector(handlerightbar2Action)];
[rightbar1 setImageInsets:UIEdgeInsetsMake(0, -30, 0, -50)];
self.navigationItem.rightBarButtonItems = [NSArray
arrayWithObjects:rightbar2, rightbar1, nil];
Is this navigation bar you added in interface builder or it is from navigation controller (either pushed or root view controller)?
If you can attache an image of the UI view controller from interface builder, it will give more details of the issue.

In iOS 11 Navigation item's titleview, barbutton items are not displaying (Using Xcode 9)

Working in a iPad application(Objective-c), which showed the navigation item's titleview, barbuttonitems in previous iOS versions. But it is not displaying in iOS 11 (Using Xcode 9). I'm using xib not storyboard.
self.editButton = [[UIBarButtonItem alloc] initWithTitle:#"Create Call" style:UIBarButtonItemStylePlain target:self action:#selector(accountView:)];
[self.editButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
self.deleteCallButton = [[UIBarButtonItem alloc] initWithTitle:#"Delete" style:UIBarButtonItemStylePlain target:self action:#selector(deleteCall:)];
[self.deleteCallButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:sliderBarItem, self.deleteCallButton, self.emptySeparatorButton1, self.editButton, self.emptySeparatorButton2, self.createOrderButton, nil];

How to create Previous/Next buttons above keyboard like in Safari

I'm trying to add Previous/Next buttons above the keyboard like in mobile Safari. There are a lot of questions about that here on StackOverflow, but most answers are to use inputAccessoryView.
I tried that and it looks like this:
Is there anyway to have the buttons in the toolbar bellow, like it works in mobile Safari??
This is how it looks like in Safari:
It seems what I was looking for is inputAssistantItem.
It allows you to add and change buttons in the keyboard's shortcut bar.
UIBarButtonItem* nextButton = [[UIBarButtonItem alloc]
initWithImage:nextImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(nextField:)];
UIBarButtonItem* previousButton = [[UIBarButtonItem alloc]
initWithImage:previousImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(previousField:)];
NSArray *buttonGroups = #[[[UIBarButtonItemGroup alloc]
initWithBarButtonItems:#[previousButton, nextButton]
representativeItem:nil]];
textField.inputAssistantItem.trailingBarButtonGroups = buttonGroups;
UIBarButtonItem *previous = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:103 target:self action:#selector(previousButtonTapped:)];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixedSpace setWidth:6.0];
UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:104 target:self action:#selector(nextButtonTapped:)];

UIBarButtonItem Not Working Input Accesory View iOS 7

I have a dismiss button that is a UIBarButtonItem, which is added to a UIToolbar, which is added to a text boxes inputAccessoryView.
It worked find in iOS 6, but since iOS 7 the Button doesn't act like a button, its just text.
Here is what it looks like in iOS 6.
Here is what it looks like in iOS 7
It doesn't act like a button anymore, and when I try to click it I just click the icon behind the Dismiss text.
Here is the code for this portion of the app:
self.searchBox.clearButtonMode = UITextFieldViewModeWhileEditing;
self.searchBox.returnKeyType = UIReturnKeySearch;
self.searchBox.delegate = self;
UIToolbar* searchToolbar = [[UIToolbar alloc]init];
searchToolbar.tintColor = [UIColor blackColor];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithTitle:#"Dismiss" style:UIBarButtonItemStyleDone target:self action:#selector(doneWithKeyboard)];
[searchToolbar setItems:[NSArray arrayWithObjects:flexibleSpace, doneButton, nil]];
self.searchBox.inputAccessoryView = searchToolbar;
Any help will be appreciated.

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...

Resources