I need to add unicode characters like "îăâșț" in my textfield, but i notice that if textfield is without border you can see adjusting effect and if textField has border the behaviour is as expected no adjusting.
I have tried to add border with white color but there is some shadow left, Also tried self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
How can I have the same behaviour for UITextField without border as UITextField with border?
So after playing with settings i notice if you adjust the content insets by overriding:
- (CGRect)textRectForBounds:(CGRect)bounds
- (CGRect)editingRectForBounds:(CGRect)bounds
or simply by adding a left View
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
self.textFieldName.leftView = paddingView;
self.textFieldName.leftViewMode = UITextFieldViewModeAlways;
and also keep in mind that self.textField.minimumFontSize should be smaller otherwise the jumping effect will persist
Related
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.
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 UITextField in which I want to add an image on the left side. I do this using UIImageView which is set in leftView property of UITextField. The image is resized in Image View to proper size. The problem is that it is stick to the border. How can I set left indent of the image. I suppose that one solution is to set some blank space in the left side of the image, but I want to use indent. Also I want some indent after the image, so the text is not so close to it.
I use following code:
[textField setLeftViewMode:UITextFieldViewModeAlways];
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 37, 20)];
imageView1.image = [UIImage imageNamed:#"custom_image"];
textField.leftView = imageView1;
You can set the UIImageview frame more than the original UIImage and set the UIImageview contentMode property to centre.
Please refer below answer.
UIImageView *imgSearch=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 28)]; // Set frame as per space required around icon
[imgSearch setImage:[UIImage imageNamed:#"search.png"]];
[imgSearch setContentMode:UIViewContentModeCenter];// Set content mode centre
self.tfSearch.leftView=imgSearch;
self.tfSearch.leftViewMode=UITextFieldViewModeAlways;
You need subclass UITextField and implement in it
- (CGRect)leftViewRectForBounds:(CGRect)bounds
Maybe you should have a subclass UITextField and overrides
- (CGRect)leftViewRectForBounds:(CGRect)bounds;
- (void)drawTextInRect:(CGRect)rect;
These will change the rect for the leftView .
I am working on an iOS application where I have subclassed my UITextField in order to set the colour of my placeholder text. I have also centered it horizontally, but my problem is that my placeholder text is not centered vertically, and for some reason, the cursor is not centered within the placeholder text, but instead appears just after the very first character of the placeholder text.
My method in my subclass of UITextField which I override in order to set the colour of the placeholder text and center the text horizontally looks like this:
- (void)drawPlaceholderInRect:(CGRect)rect {
// Set colour and font size of placeholder text
[[UIColor whiteColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:28] lineBreakMode:UILineBreakModeMiddleTruncation alignment:NSTextAlignmentCenter];
}
Here is my code where I create and set up my UITextField:
_field = [[CustomTextField alloc] initWithFrame:CGRectMake(190, 300, 644, 64)];
_field.delegate = (id)self;
[_field becomeFirstResponder];
[_field setBackgroundColor:[UIColor darkGrayColor]];
[_field setTextColor:[UIColor whiteColor]];
[_field setPlaceholder:#"Enter First and Last Name"];
[[_field layer] setMasksToBounds:8.0f];
[[_field layer] setBorderColor:[[UIColor grayColor] CGColor]];
[[_field layer] setBorderWidth:1.0f];
[_field setFont:[UIFont fontWithName:#"Arial" size:25]];
[_field setReturnKeyType:UIReturnKeyDone];
[_field setTextAlignment:NSTextAlignmentCenter];
_field.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.view addSubview:_field];
I initially subclassed my UITextField because while everything looked fine, my placeholder text for some reason was grey instead of white (which I set as the text colour for the textfield). Ironically, the placeholder text was centered both vertically AND horizontally, AND the cursor was centered. So in order to correct the placeholder text colour, I subclass the UITextField, only to open up more problems now.
Is there a way that I can now center the placeholder text vertically, as well as have the cursor centered as well? Better still, is there a way for me to change the grey colour of the placeholder text to white without having to subclass it? This would be ideal.
I think you forgot to implement in .h ( not in your custom TextField class )
#interface YourView : UIView<UITextFieldDelegate>
and the delegate method didn't called ! The placeholder textcolor must be that color what you want, if you do it like this.
#import "YourView.h"
#implementation YourView
// .....
_field.delegate = self;
_field.textAlignment = NSTextAlignmentCenter;
// ....
You can add some vertical padding like this:
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 30)];
_field.leftView = paddingView;
_field.leftViewMode = UITextFieldViewModeAlways;
from apple developer library:
leftView
The overlay view displayed on the left side of the text
field.
#property(nonatomic, retain) UIView *leftView
Discussion You can use
the left overlay view to indicate the intended behavior of the text
field. For example, you might display a magnifying glass in this
location to indicate that the text field is a search field.
The left overlay view is placed in the rectangle returned by the
leftViewRectForBounds: method of the receiver. The image associated
with this property should fit the given rectangle. If it does not fit,
it is scaled to fit.
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.
link to apple developer library / UITextField
I hope this helps !
I have a textField which I want to edit by using a custom input view within a popOver. So I am preventing the keyboard from appearing but setting a dummy view for the textViews input view, i.e
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
[self.textFieldStartBid setInputView:dummyView];
This works fine, I tap on the textField, the keyboard stays hidden and the popoverController appears. The problem arises if you had previously split the keyboard, now when you tap on the textField I get a bordered transparent view appearing at the bottom of the screen which covers the entire width and is about 50 pixels high.
I have more than one viewController using this technique to hide the keyboard and all VCs have this exact same issue with the split keyboard.
It seems I am half way there to stopping the split keyboard from appearing but not fully, has any experienced this or no or any possible solutions?
Thanks,
Stewart.
Try using CGRectMake(0, 0, 0, 0) for your dummyView initialization:
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
This worked fine for me.