UITextField Number Pad not working - ios

_text = [[UITextField alloc] initWithFrame:CGRectZero];
_text.font = [Styles bodyFont];
_text.text = ((EditTextBubble *)(toEdit.bubble)).textLabel.text;
if ([_text.text isEqualToString:[#"E.g. " stringByAppendingString:((EditTextBubble *)toEdit.bubble).placeholder]]) _text.text = #"";
_text.textAlignment = NSTextAlignmentLeft;
_text.delegate = self;
_text.userInteractionEnabled = NO;
[self addSubview:_text];
_text.keyboardType = UIKeyboardTypeNumberPad;
I'm trying to get the number pad (http://cdn.arstechnica.net/wp-content/uploads/2013/09/keypad.png) to work for UITextField but all I get is the normal keyboard on the numbers page, not that google image above. How do you get it to work? This is on iOS 7 and on ipod/ipad, and without the nib file.

If you need to display a numpad keyboard on iPad, you will need to build your own (or use an open source), and set the text view's inputView to the view you created. But don't be alarmed, this is quite easy to do.
On iOS7, use UIInputView to get a similar look and background to the native keyboard.
An example of Apple's custom numeric keyboard on iPad in their Numbers app:

Related

keyboard displaying in old layout

I have following settings for my textfield
_urlSearchTextFieldFirst.backgroundColor = [UIColor clearColor];
_urlSearchTextFieldFirst.placeholder = #"url";
_urlSearchTextFieldFirst.delegate = self;
_urlSearchTextFieldFirst.keyboardType = UIKeyboardTypeURL;
_urlSearchTextFieldFirst.keyboardAppearance = UIKeyboardAppearanceDefault;
_urlSearchTextFieldFirst.returnKeyType = UIReturnKeyGo;
_urlSearchTextFieldFirst.autocorrectionType = UITextAutocorrectionTypeNo;
_urlSearchTextFieldFirst.autocapitalizationType = UITextAutocapitalizationTypeNone;
and the keyboard its displaying looks some old way some way zoomed.
You need to add iPhone X launch screen in asset folder .
Then Keyboard will work properly
And For layout
You need to use safe layout , Go to storyboard , Select ViewController to make safe layout which is compatible for iPhone X

How to make IOS keyboard compact like YikYak or Vine

For now, i'm using the system default keyboard, and below is wat my keyboard looks like
_dummy = [UITextField new];
_dummy.keyboardAppearance = UIKeyboardAppearanceLight;
_dummy.keyboardType = UIKeyboardTypeDefault;
_dummy.autocorrectionType = UITextAutocorrectionTypeNo;
Here, the first screenshot is what my keyboard looks like, very old school, the next two are from YikYak and Vine.
The difference is obvious (i.e. The spacing, letter size). I want to make my keyboard as compact as Vine or YikYak's. Any thoughts?

Keep a hardware (bluetooth) keyboard from overriding an inputView in iOS 8

I have a UITextField that uses a custom UIPickerView in its inputView to restrict the user to a few options, functioning analogous to a dropdown list. When used with a hardware keyboard connected via bluetooth, the hardware keyboard overrides (and hides) my inputView. The associated inputAccessoryView remains, however. When press the "keyboard" button on my hardware keyboard (which would normally display the default on-screen keyboard for a vanilla UITextField), everything works as expected. (By which I mean my inputView is visible again.) In prior version of iOS (i.e. 7 and below), the inputView was always visible when called.
I have temporarily solved the problem by setting the UITextField's UIKeyboardType from UIKeyboardTypeDefault to UIKeyboardTypeTwitter, but this will only work while the hardware keyboard is not recognized as the default for that particular UIKeyboardType. Code is pickerTextField.keyboardType = UIKeyboardTypeTwitter; (See about 2/3 of the way into the code below.) Upon further testing, this partial solution isn't nearly as useful as it seems.
How can I correctly display my inputView in all situations while using a hardware keyboard?
Relevant code snippet:
-(int)setUpPickerWheelAtXLoc:(int)xLoc andYLoc:(int)yLoc {
int qwidth = width - (xLoc - FORMBORDERLEFT);
// Set up inputView (pickerView) to replace the keyboard
self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, height)];
self.pickerView.delegate = self;
self.pickerView.dataSource = self;
self.pickerTextField = [[UITextField alloc] initWithFrame:CGRectMake(xLoc, yLoc, qwidth, 32)];
self.pickerTextField.delegate = self;
pickerTextField.borderStyle = UITextBorderStyleRoundedRect;
pickerTextField.layer.borderWidth = 0.3f;
pickerTextField.layer.borderColor = [[UIColor blackColor] CGColor];
pickerTextField.textColor = [UIColor blackColor];
pickerTextField.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
pickerTextField.placeholder = #"Tap to choose from list...";
// Add pickerView as inputView
pickerTextField.inputView = self.pickerView;
pickerTextField.keyboardType = UIKeyboardTypeTwitter; // Suggested temporary solution
// Setup inputAccessoryView (Done button)
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[doneButton addTarget:self action:#selector(pickerDoneButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[doneButton setTitle:#"Done" forState:UIControlStateNormal];
doneButton.titleLabel.font = [UIFont systemFontOfSize:XXLARGEFONTSIZE];
doneButton.frame = CGRectMake(0,0,100,44);
[doneButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
doneButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,20);
doneButton.backgroundColor = [UIColor lightGrayColor];
pickerTextField.inputAccessoryView = doneButton;
return xLoc + qwidth;
}
Additional Info: After checking a few other places, I have confirmed that this is happening in at least one Apple product as well. (In the "Create New Apple ID" app/page on an iPhone 6 in 8.0.2. See the Date of Birth pickerviews for Month and Day.)
The issue was fixed by Apple in the iOS 8.1 update.

CGRectMake doesn't work

I'm working on example from "iOS Programming Cookbook", based on iOS 7. I need to create UITextField and add it to ViewController.
In ViewController.m I have:
- (void) viewDidLoad {
[super viewDidLoad];
[self createField];
}
- (void) createField {
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(20.0f, 35.0f, 280.0f, 30.0f)];
self.textField.translatesAutoresizingMaskIntoConstraints = NO;
self.textField.borderStyle = UITextBorderStyleRoundedRect;
self.textField.placeholder = #"Enter text to share";
self.textField.delegate = self;
[self.view addSubview:self.textField];
}
On screenshot from book textField appears in the middle of screen's width under the status bar, but when I run it textField appears on the top left corner of screen behind the status bar.
Maybe the problem is, that I run app on iPhone 6 simulator with iOS 8. But I don't know how to solve it.
Thanks!
Using self.textField.translatesAutoresizingMaskIntoConstraints = NO; is pretty much telling the object that it doesn't really care about the frame but relies more on the constraints that you give it. Setting it to YES takes the frame and automatically applies constraints to it to mimic the frame that you give it.
For example it would apply the constraints to have the frame appear at: CGRectMake(20.0f, 35.0f, 280.0f, 30.0f). When setting it to NO use NSLayoutConstraint and create the constraints programatically.
But in your case just remove the line
self.textField.translatesAutoresizingMaskIntoConstraints = NO;
because it is set to YES by default.

Cannot make programmatically created UITextField editable (iOS)

I created a UITextField programatically, (I do not use storyboard) and added it as a subview to ViewController with this code:
#interface ViewController ()
#property (nonatomic, strong) UITextField *searchLocationBar;
#end
...
#synthesize searchLocationBar;
...
self.searchLocationBar = [[UITextField alloc] init];
self.searchLocationBar.frame = CGRectMake(0.0f, 0.0f, 320.0f, 40.0f);
self.searchLocationBar.delegate = self;
self.searchLocationBar.borderStyle = UITextBorderStyleRoundedRect;
self.searchLocationBar.placeholder = #"a temporary placeholder";
self.searchLocationBar.userInteractionEnabled = YES;
self.searchLocationBar.clearButtonMode = UITextFieldViewModeAlways;
[self.view addSubview:self.searchLocationBar];
However, I cannot enter any text - nothing happens, when I tap on a textfield. It's not overlapped by any other view.
I've checked UITextfield not editable-iphone but no effect
I'm newbie and totally sure I simply miss something - please advice.
Thanks!
EDIT:
One more thing: I have a Google Maps GMSMapView assigned to self.view as
self.view = mapView_; as written in Google API documentation.
After some tests I found that with this declaration all controls work perfectly, but not textfields. I would prefer not to move a map view to any subview as I will need to rewrite lots of things.
Can someone please add any suggestions?
you forget add:
[self.view bringSubviewToFront:self.searchLocationBar];
In Xcode 5 your code should work.Better you check your Xcode version.May be the problem with your code with Xcode versions.You can try by following way.
UITextField *lastName = [[[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];
[self.view addSubview:lastName];
lastName.placeholder = #"Enter your last name here"; //for place holder
lastName.textAlignment = UITextAlignmentLeft; //for text Alignment
lastName.font = [UIFont fontWithName:#"MarkerFelt-Thin" size:14.0]; // text font
lastName.adjustsFontSizeToFitWidth = YES; //adjust the font size to fit width.
lastName.textColor = [UIColor greenColor]; //text color
lastName.keyboardType = UIKeyboardTypeAlphabet; //keyboard type of ur choice
lastName.returnKeyType = UIReturnKeyDone; //returnKey type for keyboard
lastName.clearButtonMode = UITextFieldViewModeWhileEditing;//for clear button on right side
lastName.delegate = self; //use this when ur using Delegate methods of UITextField
There are lot other attributes available but these are few which we use it frequently.if u wanna know about more attributes and how to use them refer to the following link.
You can also make property for UITextField.Either way should work fine in Xcode.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html

Resources