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
Related
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
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.
How to place UILabel in the center of navigation bar in XCode 6? Is it possible at all? I can place here, for example, UIButton, but unable to place UILabel. If no, what can I do then? Place a UIButton with the appropriate text and make it non-clickable?
Thanks in advance.
In Xcode 6 if you want to put a label inside the UINavigationBar firstly you have to put a UIView there then put the UILabel inside the UIView (this is from the Storyboard btw).
If you do not put the UIView first then the UILabel will never get put onto the UINavigationBar.
Create a UIView and add UILabel as it's subview and then set your NavigationItem's titleView as previously created UIView.
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 40)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 40)];
label.text = #"Hello";
label.textAlignment = NSTextAlignmentCenter;
[view addSubview:label];
self.navigationItem.titleView = view;
Note: Don't forget to set your own frame values to get better result.
Just make sure you try viewWillLayoutSubviews method instead of viewDidLoad that was what worked for me. Cheers!
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 have a table view full of buttons. A label is outside the tableview serving as heading. I want to shove it inside the table view, on top of course, without changing it to button. In other words I want to move it inside the tableview, but on top and not as a button,as a heading.
The label in question says "Select all things that apply to your home"
For code please see Set title labels of buttons in table view from an array full of strings
For Screenshot pls visit http://i60.tinypic.com/2qmf4wl.png
How about this?
UIView *headerView;
UILabel *labelView;
labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
labelView.font = [UIFont fontWithName:#"Trebuchet MS" size:22.0];
labelView.backgroundColor = [UIColor clearColor];
labelView.text = #"* Your important note here.";
labelView.textColor = [UIColor blackColor];
[headerView addSubview:labelView];
yourTableView.tableHeaderView = headerView;
It's hard to add a label to a tableviewcontroller. Two options I can think of:
Make "Select all things that apply to your home" your navigation item title. (you can do this right in the storyboard)
Place a table view in a normal view controller and leave enough space on top for a label. (again, you can drag a normal table view into a view controller in a storyboard)
Hope it helps!
you can creat a subclass of UITableViewCell and custom the cell for the tabe