backBarButtonItem(leftbackButtonItem) Style Issue - iphone

I want change other UIBarButtonItem. but, retain buttonItemStyle...
I want the original buttonItemStyle... only change inner content
How make BackBarButtonItemStlye?
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"section" style:<??? what is style?> target:self action:#selector(popView:)];
how i get the image button style?
plz.. help ^^
I never find this style.
api only support below style... not backbuttonstyle...
UIBarButtonItemStylePlain,UIBarButtonItemStyleBordered,UIBarButtonItemStyleDone,
[self navigationItem] setBackBarButtonItem:backBarButtonItem]; is Not Want...
[self navigationItem] setLeftBarButtonItem:backBarButtonItem]; is Want..
because my custom buttonItem target, action is not nil...
my buttonItem is change custom item...
setBackBarButtonItem is only use default Action (now ViewController pop)
setLeftBarButtonItem is use any custom action
ex:
[ self navigationController] popToRootViewController];
[[self navigationController] popToViewController:[[[self navigationController] viewControllers] objectAtIndex:2] animated:YES];
big issue is not supported cocoa API backBarButtonItemStyle(image refrence)...
how to solve this problem?
only draw a illustrator backBarButtonItemStyle image?

You need to change the backBarButtonItem of the parent view controller. Use UIBarButtonItemStylePlain as a style and UIKit will automatically use the back appearance.

This style is not customizable. You need to create the bar button with some image that looks like the back button.

Related

UITextView next and previous Button over the Keyboard

how can I implement "Next" and "Previous" Button's over the keyboard.
I use UITextView and with click on "Next" the Next TextView gets focus, Previous the last TextView.
I do not found any tutorial on the Internet.
I hope everybody can help me.
Please use this custom control
COCOA
If you need any help, let me know.
This controlis very simple to use.
Updated Answer
Change the Button Label
Go to BSKeyboardControls.m file & make the following Changes
On line no. 42
[self setSegmentedControl:[[UISegmentedControl alloc] initWithItems:#[ NSLocalizedStringFromTable(#"<", #"BSKeyboardControls", #"Previous button title."),
NSLocalizedStringFromTable(#">", #"BSKeyboardControls", #"Next button title.") ]]];
On line No. 51
[self setDoneButton:[[UIBarButtonItem alloc] initWithTitle:NSLocalizedStringFromTable(#"Ok", #"BSKeyboardControls", #"Done button title.")
style:UIBarButtonItemStyleDone
target:self
action:#selector(doneButtonPressed:)]];
///// ********* Update 2 ********* ////////////
SET Image for Previous & Next
Just add the following code in BSKeyboardControls.m after line no. 52
[self.segmentedControl setImage:[UIImage imageNamed:#"add.png"] forSegmentAtIndex:BSKeyboardControlsDirectionPrevious];
[self.segmentedControl setImage:[UIImage imageNamed:#"add.png"] forSegmentAtIndex:BSKeyboardControlsDirectionNext];
change BSKeyboardControls.m file & make the following Changes
remove this one
// [self setRightArrowButton:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 target:self action:#selector(selectNextField)]];
add this
[self setRightArrowButton:[[UIBarButtonItem alloc]initWithTitle:#"Next" style:UIBarButtonItemStylePlain target:self action:#selector(selectNextField)]];

add custom switch to iphone view

I am using the following code to create a custom switch:
UISegmentedControl* switchView=[[UISegmentedControl alloc]
initWithItems:[[NSMutableArray alloc] initWithObjects:#"On",#"Off",nil]];
[switchView setFrame:CGRectMake(20,365,140,28)];
switchView.selectedSegmentIndex=0;
switchView.segmentedControlStyle=UISegmentedControlStyleBar;
[switchView setImage:[UIImage imageNamed:#"onSelected.png"] forSegmentAtIndex:0];
[switchView setImage:[UIImage imageNamed:#"off.png"] forSegmentAtIndex:1];
[switchView addTarget:self action:#selector(checkOnOffState:) forControlEvents:UIControlEventValueChanged];
I would now like to add this control to one of my screens (I believe the correct term is ViewController?). How would I do this in Xcode 4.3?
I looked at a few other posts and was not able to find anything that works. For example, How do I add a custom view to iPhone app's UI? suggested something along the lines of
[[myVC view] addSubview:myView];
and How to customize UISwitch button in iphone? suggested
self.navigationItem.titleView=switchView;
If possible, could you also explain why these approaches did not work? Thanks.
You need to create a class for your switch which is subclass of your UISegmentControl ,
Else you can add this code in your vc directly as well.
Add this code in its initWithFrame method
and then use it in your VC
-(void)viewDidLoad{
urCustomSwitch = [urCustomSwitch alloc] initWithFrame:CGRectMake(20,365,140,28)];
[self.view addSubview:urCustomSwitch];
}
This shall serve your purpose if you are to create custom reusable class.
If you add this switch control i.e. UISegmentedControl in InterfaceBuilder (.xib file)
This task will be much easier for you.

How to get keyboard with Next, Previous and Done Button?

I want to have a keyboard which has a Next,Previous and Done button on top of it.
I have seen that in many apps.
Especially where there are forms to be filled.
I want to achieve something similar to above keyboard
How can I get that?
You'll find the answer on this other post.
I checked the iOS Library and the inputAccessoryView of a UITextField is exactly what you're looking for !
Hope this helps !
I just created a class called BSKeyboardControls which makes it very easy to add the controls to a keyboard. The class, instructions and example code can be found here at GitHub.
The controls works for text fields and text views and are optimized for both iPhone and iPad.
-(BOOL)textFieldShouldBeginEditing: (UITextField *)textField
{
UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
keyboardToolBar.barStyle = UIBarStyleDefault;
[keyboardToolBar setItems: [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Previous" style:UIBarButtonItemStyleBordered target:self action:#selector(previousTextField)],
[[UIBarButtonItem alloc] initWithTitle:#"Next" style:UIBarButtonItemStyleBordered target:self action:#selector(nextTextField)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(resignKeyboard)],
nil]];
textField.inputAccessoryView = keyboardToolBar;
}
- (void)nextTextField {
if (textField1) {
[textField1 resignFirstResponder];
[textField2 becomeFirstResponder];
}
}
-(void)previousTextField
{
if (textField2) {
[textField2 resignFirstResponder];
[textField1 becomeFirstResponder];
}
}
-(void)resignKeyboard {
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
}
I have a utility class that basically does this for you.
https://github.com/kalvish21/CustomKeyboard
The idea is very simple. You have to add an accessory tool bar with bar button items on it. There's a delegate which defines where what that button will do.
https://github.com/hackiftekhar/IQKeyboardManager
This is the best keyboard handler I have seen so far. Very excellent way to manage Text inputs.
Some of its features
1) ZERO LINE OF CODE
2) Works Automatically
3) No More UIScrollView
4) No More Subclasses
5) No More Manual Work
6) No More #imports
This is a custom control which is placed directly above the keyboard. I think a UIToolbar can be used for that.
Previous and next passes around the firstResponder of the textFields and Done will do the resign as well as hide the toolbar.
To match the keyboard animation have a look at this code I found or at SO: "What is the iPhone's default keyboard animation rate?"
I have created a repository with an implementation of this feature that works on iPhone/iPad in all orientations and highly customizable.
As mentioned in other answers, it's the inputAccessoryView that you're looking for.
I would like to add an alternative way here, by using this cocoapods:
pod 'UITextField-Navigation'
All UITextFields will have two additional properties: nextTextField and previousTextField. You can then simply connect the nextTextField in the Interface Builder and the Previous, Next and Done buttons are added automatically for you, all functional, no more code is needed, no subclassing.
You can also customize the UI, add more buttons, etc as you want to.

Popover does not open over button

The layout...
I have a UIToolbar that loads a view with several buttons. One of those buttons, on the onpress should display a popup.
It does. However, the popup seems to open up at 0,0.
-(IBAction)FilterButtonPressed:(id)sender
{
if (_FilterViewController == nil) {
self.FilterViewController = [[[FilterViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
_FilterViewController.filterViewDelegate = self;
self.FilterViewPopover = [[UIPopoverController alloc] initWithContentViewController:_FilterViewController];
}
NSLog(#"Button...: %#",NSStringFromCGRect(self.FilterButton.frame));
[self.FilterViewPopover presentPopoverFromRect:self.FilterButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
The NSLog reads:
Button...: {{0, -4.38184}, {0, 4.76182e-39}}
which is... just weird..
Any suggestions as to why the FilterButton doesn't know where it is?
Any suggestions as to why the FilterButton doesn't know where it is?
Looks like it's uninitialized / not properly initialized. Are all your outlets set up properly? Whenever "my xyz object is not behaving properly" happens, checking your outlets is usually the first order of business (note that the action can be hooked up from a button, but your link to the button from your class may not be. Try printing the state from the "sender" cast to "UIButton *".

navigationItem.prompt & UIImagePickerController

Is it possible to make calls to navigationItem on a UIImagePickerController? Specifically, the image picker? Below I've linked an image of what I'm trying to achieve ( screen shot taken from another app doing the same thing). Once the user selects an image from the picker the navigationItem.prompt is set and, though I think it might be a HIG violation, the right bar button is changed from the standard cancel button. I can set the prompt on a "normal" view no problem with:
self.navigationItem.prompt = myString;
But this does not seem to work when I try to use it in the context of a picker with:
myPicker.navigationItem.prompt = myString;
I've tried using it when the picker is created and also in didFinishPickingMediaWithInfo: which is really where I need to set it as I'm letting the user select multiple images instead of dismissing the picker as soon as one image is selected. Nothing seems to work.
Here's a image of the desired behavior:
http://i51.photobucket.com/albums/f353/zoso5th/after.png
Someone answered this for me on the Apple dev forums:
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";
I wasn't correctly accessing the navbar.
Someone answered this for me on the Apple dev forums:
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";
I wasn't correctly accessing the navbar.
Use the code after calling 'presentModalViewController'.....like below...
[controller presentModalViewController:imagePickerController animated:YES];
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = #"Some new prompt";