HI all,
I am having a 2 textFeild and 1 textview.
out of 2 textfeild,one textfield requires number to be filled in there.
so for that i hv provided numeric keyboard.
i m not able to dismiss numeric keyboard,since i cant c any option to hit the numeric keyboard dismiss.
is it possible to dismiss numeric keyboard
??
if yes than can anyone guide me through.
regards
shishir
You have 2 options: add a return keyboard in a numpad keyboard or catch the event of user select another textfield and dismiss the numpad there. Here is the link to add a return (done) button to a numpad keyboard. Done in numpad keyboard
There is no button to dismiss the numeric keypad (although on the iPad you can do this). You will have to call [textfield resignFirstResponder] in code if you want to do this yourself.
There is one other possible way. For those who are looking for something perfect then vodkhang's answer is very good. But if you are looking for some work-around then textField.inputAccessoryView can be useful. The idea is to show done button in inputAccessoryView. Following is sample code
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 25)];
view.backgroundColor = [UIColor grayColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:#"Done" forState:UIControlStateNormal];
button.frame = CGRectMake(320-60, 0, 60, 25);
[view addSubview:button];
textField.inputAccessoryView = view;
There are few things to be noted.
Width of accessoryView is equal to screen width. So you need to write some code for managing look and feel according to your application.
You can give any kind of look to you dome button. And here you don't have to worry about Apple's design changes in keyboard.
Related
I made a button already. When I click it, it becomes big but letter is not in good position. I want to put another button inside the big button. How can I do this ?
If you just wish to add a second button as a subview of the first button, you can use this:
UIButton *mySmallButton = [[UIButton alloc] initWithFrame:CGRectMake:(0, 0, 50, 50)];
[mySmallButton setBackgroundColor:[UIColor redColor]];
[myBigButton addSubview:mySmallButton];
However, if you're just looking to modify the text size/alignment of the first button once it has grown you can use these:
[[myBigButton titleLabel] setTextAlignment:UITextAlignmentCenter];
[[myBigButton titleLabel] setFont:[UIFont systemFontOfSize:24]];
I am developing a Universal app, and there is a UIButton in it which works fine with iPhone but when I click it in iPad it requires many click attempts to get the touch event occur.
e.g. after 5-6 clicks it executes click event.
Below is UIButton code. Please help.
UIView *footer = [[[UIView alloc] initWithFrame:(CGRectMake(0, 0, self.tableView.frame.size.width, 54))] autorelease];
float buttonWidth = (int)((self.tableView.frame.size.width - 12 - 12) / 3);
float buttonHeight = 44;
if (clientState.Devicetype == 1) // 1=Ipad
buttonHeight = 90;
cash = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
cash.frame = CGRectMake(6, 10, buttonWidth, buttonHeight);
[cash setTitle:#"Cash" forState:UIControlStateNormal];
[cash setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[cash addTarget:self action:#selector(handleCash:) forControlEvents:UIControlEventTouchUpInside];
cash.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
if (clientState.Devicetype == 1) // 1=Ipad
{
cash.titleLabel.font = [UIFont systemFontOfSize:28];
}
[footer addSubview:cash];
self.tableView.tableFooterView = footer;
You should check to make sure that your buttons are the correct size:
[cash sizeToFit]
I've experienced that if some other view is blocking it (and you click on that part of your button it won't fire off the event) it will take several clicks because you eventually press the button where it's not being covered. So make sure no other frame/bounds is over the top of your button and make sure your button is sized correctly.
I agree with #Inturbidus that it's probably another transparent view covering part of the button. I find the best way to troubleshoot this is to change the background color on all my other views (scrollviews, etc) to make sure they are behaving like I think they are. Sometimes it will surprise you when you see where they are actually positioned with background color turned on.
I have a UIToolbar that I've customized with my own background image. Consequently, the built-in UIBarButtonItem appearance doesn't work for me, so I'm using images that are already prepared to show in the bar. I create a custom button item with this method:
+ (UIBarButtonItem *)customWithImage:(UIImage *)image enabled:(BOOL)enabled target:(id)target action:(SEL)selector {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//I've tried different values for the frame here, but no luck
button.frame = CGRectMake(0, 0, 44, 44);
button.enabled = enabled;
button.showsTouchWhenHighlighted = YES;
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
[button setImage:image forState:UIControlStateNormal];
UIBarButtonItem *it = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
//Tried changing this, to no avail
it.width = 32.f;
return it;
I have one button on the left and one on the right and I'm trying to make it so that if you tap on the far left or far right of the UIToolbar, the corresponding button is tapped. However, with these custom buttons, the hit targets do not extend all the way to the edges of the UIToolbar, but are inset from the sides:
http://skitch.com/andpoul/d1p8g/hit-targets
Any help greatly appreciated!
UIBarButtonItem.width might be ignored if you're using a custom view (it probably just uses the width of the view).
A lame hack is to make the toolbar wider (so it sticks outside the screen) and add transparent edges to the background image to compensate. This brings the buttons closer to the edge of the screen.
An alternative is just to use a UIImageView with UIButton subviews.
I think the only way you will have to go is to make buttons wider (change image by adding some from left for one and right for another) and adjust size...
alt text http://img216.imageshack.us/img216/2288/problem11.png
As given in the picture, I have an search bar in my application.
Now I want to handle my custom action on Cancel Taped.
-> On Cancel Taped -> PopViewController
-> On Cancel Taped -> Clear Search Text & Hide Search Bar Keyboard.
I don't know how to handle Cancel Tap?
Thanks in advance for helping me.
Ok ! I tried Something Different. I added a new button on Cancel Button.
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor=[UIColor clearColor];
[btn setFrame:CGRectMake(260, 5, 53, 32)];
[btn addTarget:self action:#selector(onCancelSearch:) forControlEvents:UIControlEventTouchUpInside];
[searchBar addSubview:btn];
Now. See Following image. but it is with RoundedRect Type, Instead Use TypeCustom - so it will become invisible.
alt text http://img269.imageshack.us/img269/4337/problem12e.png
Is it possible to set up a UITextField with a leftView so that if a user clicks into the UITextField the keyboard shows but if they click on an icon in the leftView another method is called (i.e., one that displays a UIPickerview)?
Have you checked that the leftFieldViewMode is set to something other than never
[textField setLeftViewMode:UITextFieldViewModeAlways];
Instantiate a button as u do normaly
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0,0,30,30)];
[btn setTitle:#"title" forState:UIControlStateNormal];
[btn addTarget:self action:#selector(BtnClick) forControlEvents:UIControlEventTouchUpInside];
Instantiate a textfield as you do normally
UITextField *txtfield1=[[UITextField alloc]initWithFrame:CGRectMake(10, 10,300,30)];
[txtfield1 setBackgroundColor:[UIColor grayColor]];
[txtfield1 setPlaceholder:#" Enter"];
To set a view in left side(there is right view also available)
[txtfield1 setLeftView:btn];
if u want the view to show always then below code does it
[txtfield1 setLeftViewMode:UITextFieldViewModeAlways];
if u want the view to show never then
[txtfield1 setLeftViewMode:UITextFieldViewModeNever];
if u want the view to show if the textfield is not edited then below
[txtfield1 setLeftViewMode:UITextFieldViewModeUnlessEditing];
if u want the view to show if the textfield is edited then
[txtfield1 setLeftViewMode:UITextFieldViewModeWhileEditing];
button click event and pop over
-(void)BtnClick
{
//Usual pop over coding goes here
}
Have you tried using a UIButton for this task? From the documentation for the leftView property:
If your overlay view does not overlap
any other sibling views, it receives
touch events like any other view. If
you specify a control for your view,
the control tracks and sends actions
as usual. If an overlay view overlaps
the clear button, however, the clear
button always takes precedence in
receiving events.
So create a UIButton instance, configure its appearance and actions as needed, then set it as the leftView property.