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.
Related
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.
I want both my placeholder and typed text to be aligned in the center.
I tried both of these options for the two textfields I have, but still the placeholder and whatever I type are aligned left.
self.teamA_name.textAlignment=NSTextAlignmentCenter;
self.teamB_name.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
What am I missing?
Textfields are created through IB.
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,15, 20)];
_txtCityName.leftView = paddingView;
_txtCityName.leftViewMode = UITextFieldViewModeAlways;
Use this code to set inset..This works for me
Currently I'm setting padding view width as 15...change this as your requirement and make it in the center
I have a UIButton and a UITextView, now when I write something on textview and submit the button the textview content is showing over a UIView , but If I write in the text field and press enter and write in a new line and hit in the button the text is showing in one line , It is not recognizing the enter . How do I recognize "enter" in UITextView and show the text in new line ??
-(IBAction)Acceptmethodtext:(id)sender
{
textwritingoverit= [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 100)];
textwritingoverit.lineBreakMode = NSLineBreakByWordWrapping;
textwritingoverit.numberOfLines = 0;
textwritingoverit.text=imagelabeltext.text;
[imagecross addSubview:textwritingoverit];
}
where textwritingoverit is UILabel,
imagelabeltext is UITextView and
imagecross is UIView
Above I have edited my question
For textwritingoverit whenever I have text of single line it took multiple line as the width of the label is fixed but I need the text to be shown in multiple line when user add new line through UITExtview. I need flexible width of the label depending upon the text.
can anyone help me in this , how could i do so ..
Thanks
Check out: You might missed the numberOfLines property for the UILabel .
For Ex:
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;
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;
There is a UITextView in the view, the view controller is showing with Modal style. In my viewDidLoad method, I set the text of this UITextView, but, the text is not showing. Image below showing the error. Text color is black.
The weird thing is , when I long tap in the text view or tap [return] in keyboard, the text become visible. One thing I noticed is this error only occurred when the text I set is longer than the UITextView frame width, and the last word is not broken such as a long url.
I think the problem is maybe the word wrap not work correctly.
Thanks in advance.
Code like below:
UITextView *myTextView = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, 520, 220)];
myTextView.textColor = [UIColor blackColor];
myTextView.font = [UIFont systemFontOfSize:20];
myTextView.layer.cornerRadius = 5;
myTextView.delegate = self;
myTextView.text = #"long text should some like http://stackoverflow.com/posts/11200726/edit";
[self.view addSubview:myTextView];
[myTextView release];
RESOVLED. In viewDidLoad method, add code below:
CGRect tempFrame = myTextView.frame;
[myTextView setFrame:CGRectZero];
[myTextView setFrame:tempFrame];
Subclass UITextView, to a class of your own, let's say MyUITextView:UITextView.
Initialize it offscreen with
[[MyUITextView alloc] initWithFrame:CGRectZero]
In MyUITextView override the method
-(void)willMoveToWindow:(UIWindow *)newWindow
and in it, set self.frame to the proper value.
this worked for me!
Are you sure the text color is black? Also make sure that the image is behind the textView in the view hierarchy. TextView handles Word wrap automatically.
I think in this case, the viewDidLoad is getting called before modelViewController is presented.
Set the text after modalViewController is presented.
If that also not working, then after presenting model, call a method to set the text explicitly.
Check your view hierarchy. You might have added another textView above that view.
Try changing the background color of textView. It must appear is UITextView is added there. And make sure you are not adding another view as a subview above your UITextView. If the textColor is black it must be visible, wordwrap is done by default automatically unless you change the property.Also try to check the attributes settings in XIB if added and plz show the code if adding programmatically.
I think problem in:
self.view
Try add this code line at top
self.view = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
And if not will help, try remove this code line
myTextView.layer.cornerRadius = 5;