Customising the Text Field - ios

So - I am experimenting at the moment with app design.
This is my concept:
See the blue line? That should be where the users "cursor" starts and cant go negativaly behind that point, but can move positively until the end of the box.

As long as the UITextField starts after the colon and does not extend beyond the cell's trailing edge, you should have no issues. Are you laying out using code or Interface Builder?

I have done the similar UI using UITableview. Code to set the Username label for the cell in cellForRowAtIndexPath (use similar code for Password row):
tableViewCell.textLabel.text = #"Username:";
Here is the code to set the text field:
UITextField *textField = [[UITextField alloc] initWithFrame:textFieldRect];
//Insert code for text field delegate and properties e.g. keyboardType, autocorrectionType
tableViewCell.accessoryView = textField;

Related

iOS text field doesn't show placeholder text

So I have some basic textfields with a custom background, that is a line at the bottom and the rest of it it's transparent, but now the placeholders don't show anymore.
These are the text fields
And config
I have found a solution that works, you need to select the input and set the following on User Defined Runtime Attributes
It's better to do this:
if ([self.textField respondsToSelector:#selector(setAttributedPlaceholder:)]) {
self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.textField.placeholder attributes:#{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
I had the same problem. Turns out it had nothing to do with me having set borderStyle to UITextBorderStyleNone. It was caused by me subclassing UITextField to add a manually drawn border along the bottom only and failing to call the super implementation in my override of layoutSubviews. Once I had sorted that, my placeholder text was back.

How to set the text field letter slightly right side

I have two text fields, for username and password. I created designs for both uitextfield using the layer property.
When enter some text, values are displayed starting from the edge like below:
Is there any possible to move that username slightly to the right as a starting point for uitextfield?
Thanks
UITextField Class Reference, this class has a overlay views inside it like leftView and rightView so just create a blank view and add it to your textField's leftView.
Also you can check these. UITextfield leftView/rightView padding on iOS7
Text inset for UITextField?
UIView *paddingView_textFieldFullName = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 35)];
yourTextFieldName.leftView = paddingView_textFieldFullName;
yourTextFieldName.leftViewMode = UITextFieldViewModeAlways;
yourTextFieldName.text = #"";
yourTextFieldName.delegate=self;
try this code,
I hope helps to you.

UITextField, set placeholder after text in ios

I need to keep the placeholder after the text, when click on the text box i need to clear only the placeholder and able to type characters.
In this Marissa is the name text and (First Name) is placeholder. Once i start editing placeholder need to clear and start editing complete text.
How can i achieve that?
I have found some similar custom textfield in the below URL. If you find this suitable, you can use it.
TUTORIAL / SOURCE
Please refer below code.
Just copy-paste below code in viewdidload()
textfield.attributedPlaceholder = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:#"Yourtext%#",Placehodertext] attributes:#{NSForegroundColorAttributeName: color}];
Assign Delegate of UITextfield to self.
textfield.delegate = self
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
textfield.text = #"Yourtext"
return YES;
}
You can not set place holder along with the text in a textfield.
But there is one alternate for this.
Textfields has something called left view which you can make readOnly view.
Try this :
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
UILabel *textLabel = [[UILabel alloc] initWithFrame:paddingView.bounds];
textLabel.text = #"Marissa";
[paddingView addSubView:textLabel];
textField.leftView = paddingView;
textField.leftViewMode = UITextFieldViewModeAlways;
Step 1:
Make the text filed attributed form xib and set the "Marisa (First Name)"
and change the color for the (First Name) as grey color .
Step 2:
And in the Textfiled DidBiginEditing method change the textField.text to "Marisa".
This could be achieved in several ways:
Use the attributedText property of UITextField instance to apply a styling for different parts of the text. Here you need to properly define the property each time a user has changed the input by using delegate methods or by observing UIControl Control Events.
If the structure of the text input is fixed and predefined you could use a batch of fields to imitate a more complex/smart field. Here, for example, you need to put two fields beside. One for the last name, second for the first name. Or you can use a combination of UILabel and UITextField if one the part is not editable. Such an approach allows you to configure a separate part of a complex field as you want: different placeholders, fonts, keyboard styles, etc.

Not properly add inputAccessoryView for UITextField

There is a requirement of inputAccessoryView is for the chat application.
When I add inputAccessoryView to UITextField on tap event of UIButton. That view is set as inputAccessoryView completely but text field is not becoming first responder.
(Note: Super view of textfield is viewText.)
- (IBAction)btnOpenTextField:(id)sender
{
UIView *accessoryView=[[UIView alloc]init];
accessoryView.frame=CGRectMake(0,0, _viewText.frame.size.width, _viewText.frame.size.height);
[accessoryView addSubview:_viewText];
_txtMessage.inputAccessoryView = accessoryView;
[_txtMessage becomeFirstResponder];
}
Thanks in Advance.
You can call [_textMessage reloadInputViews], replacing [_text becomeFirstResponder].
What you want to achieve is quite not possible, this will cause recursion, alternatively what you can do is put a textfield on bottom of the screen and when the textfield is selected you can animate it up with the flow of the keyboard. i think this is an appropriate solution if i got your question correctly.

How to disable keyboard when clicking a UITextField in iOS?

I am currently developing a prototype that I want to do user testing on desktop first before loading to iPad.
I am looking for solutions to disable the keyboard after clicking a textfield. That means after clicking a textfield, user is able to enter information from the macbook keyboard directly, and the virtual keyboard that automatically shows up in the simulator will not appear. I have been through a lot of tutorials but they are all dismissing the keyboard after user entry; that is not what I am looking for. How should I hide the keyboard?
Thanks so much!
Use this:
UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
myTextField.inputView = dummyView; // Hide keyboard, but show blinking cursor
It works for UITextField and UITextView and they need to be set to editable.
What you did Here:
You created a dummy view of width=hight=0, & assigned it as the inputView of your textField.
How It works:
Instead of showing default, keyboard, now, the viewController is showing DummyView as inputView for your UITextField. As DummyView has Width=height=0, You will not see anything on the screen :)
Here is another answer which I found the same hack but with little additional supportive code snippet to hide the blinking cursor too.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO; // Hides both keyboard and blinking cursor.
}
I needed this to be done for a Quantity text field where I increase/decrease the quantity using a UIStepper view. So I needed the keyboard to be hidden always.
This will set the inputView of your textField to, basically, an empty UIView with no frame.
self.theTextField.inputView = [[UIView alloc] initWithFrame:CGRectZero];

Resources