I am getting problem in making my application compatible with iphone 4.0
My problem is like this.
When i click on a UITextview a custom keyboard is showing
UIView *test=[[UIView alloc] initWithFrame:CGRectMake(0, 160, 320, 215)];
UIExtendedKeyBoard *objKeyBoard =[[UIExtendedKeyBoard alloc] initWithFrame:[test bounds]];
objKeyBoard.tag =1001;
[test addSubview:objKeyBoard];
[objKeyBoard release];
[vTxtPoem setInputView:test];
[test release];
but when i click on particular button i need to toggle between default key board and my custom key board....i am using the following code to do this
[vTxtPoem setInputView:nil];
but it is not working ...even it is not showing default keyboard..it is still remain same custom keyboard. the control also coming to this line.
My first guess would be something like this:
[vTxtPoem resignFirstResponder];
[vTxtPoem setInputView:nil];
[vTxtPoem becomeFirstResponder];
A better way might be
[vTxtPoem setInputView:nil];
[vTxtPoem reloadInputViews];
See http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/reloadInputViews for details!
Related
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)]];
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.
I'm sure this is an easy one for someone out there. I have a UISegmentedControl which I am using as a button (so as not to have to use the nasty default button) and I am having trouble getting the target to work....code as follows
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//read.buttonType = UIBarStyleBlackOpaque;
UISegmentedControl* read = [[[UISegmentedControl alloc] initWithFrame:CGRectMake(5, 50, 310, 54)] autorelease];
[read insertSegmentWithTitle:#"Read" atIndex:0 animated:NO];
read.tintColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.9 alpha:1];
read.segmentedControlStyle = UISegmentedControlStyleBar;
[read addTarget:self action:#selector(changeFilter:sender:) forControlEvents:UIControlEventTouchUpInside];
[read setTag:1];
[self.view addSubview:read];
}
and then
-(void)changeFilter:(id)sender{
}
for some reason, clicking on the UISegmentedControl does not fire the target method.
As an addendum, is there a simpler way to make nice looking UIButtons? I don't have access to Photoshop at work (although I do have gimp installed), so a way which doesn't involve image making would be good. I can't believe that apple didn't supply nice looking UIButtons in the UI, it seems such a fundamental thing to need?
Anyway, thanks for the help mis amigos.
thanks for the answers...I've tried the fix but it still doesn't fire
I now have
[read addTarget:self action:#selector(changeFilter:) forControlEvents:UIControlEventTouchUpInside];
then
#interface
-(void)changeFilter:(id)sender;
and
#implementation
-(void)changeFilter:(id)sender{}
Note that the method is in the same class as the UISegmentedControl. Maybe I should just try using the Glass button API which was suggested, but my boss hates me using third party libraries if there is a way of avoiding it!
The selector is wrong. It should be, action:#selector(changeFilter:), And change the event to forControlEvents:UIControlEventValueChanged, as UISegmentedControl doesn't send any actions for UIControlEventTouchUpInside event.
.h file u forgot to put this
-(void)changeFilter:(id)sender;
then
change this
[read addTarget:self action:#selector(changeFilter:sender:) forControlEvents:UIControlEventTouchUpInside];
To
[read addTarget:self action:#selector(changeFilter:) forControlEvents:UIControlEventValueChanged];
The action will automatically send the sender so just try #selector(changeFilter:).
As for your second question, ios5 will help you out there... but I can't say much about that yet. For now, you can use some uibutton classes that people have made to easily make some good looking buttons. Here's one:
http://hboon.com/glass-buttons-in-iphone-apps-without-using-image-files/
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.
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.