How to set UITextField height?

IphoneIosXcodeUitextfield

Iphone Problem Overview


I am using a UITextField. I want to increase its height but I have not found any property to do this. How can I achieve this?

Iphone Solutions


Solution 1 - Iphone

You can not change the height of the rounded rect border style. To set the height, just choose any border style other than rounded border in Xcode:

enter image description here

Solution 2 - Iphone

I finally found the fix for this!

As we have found, IB doesn't allow us to change the height of the rounded corner border style. So change it to any of the other styles and set the desired height. In the code change the border style back.

textField.borderStyle = UITextBorderStyleRoundedRect;

Solution 3 - Iphone

CGRect frameRect = textField.frame;
frameRect.size.height = 100; // <-- Specify the height you want here.
textField.frame = frameRect;

Solution 4 - Iphone

If you are using Auto Layout then you can do it on the Story board.

Add a height constraint to the text field, then change the height constraint constant to any desired value. Steps are shown below:

Step 1: Create a height constraint for the text field

enter image description here

Step 2: Select Height Constraint

enter image description here

Step 3: Change Height Constraint's constant value

enter image description here

Solution 5 - Iphone

1.) Change the border Style in the InterfaceBuilder.

enter image description here

2.) After that you're able to change the size.

enter image description here

3.) Create an IBOutlet to your TextField and enter the following code to your viewDidLoad() to change the BorderStyle back.

textField.borderStyle = UITextBorderStyleRoundedRect;

Swift 3:

textField.borderStyle = UITextBorderStyle.roundedRect

Solution 6 - Iphone

  1. Choose the border style as not rounded

enter image description here

  1. Set your height

enter image description here

in your viewWillAppear set the corners as round

yourUITextField.borderStyle = UITextBorderStyleRoundedRect;

enter image description here

  1. Enjoy your round and tall UITextField

Solution 7 - Iphone

Follow these two simple steps and get increase height of your UItextField.

Step 1: right click on XIB file and open it as in "Source Code".

Step 2: Find the same UITextfield source and set the frame as you want.

You can use these steps to change frame of any apple controls.

Solution 8 - Iphone

An update for iOS 6 : using auto-layout, even though you still can't set the UITextField's height from the Size Inspector in the Interface Builder (as of Xcode 4.5 DP4 at least), it is now possible to set a Height constraint on it, which you can edit from the Interface Builder.

Also, if you're setting the frame's height by code, auto-layout may reset it depending on the other constraints your view may have.

Solution 9 - Iphone

I know this an old question but I just wanted to add if you would like to easily change the height of a UITextField from inside IB then simply change that UITextfield's border type to anything other than the default rounded corner type. Then you can stretch or change height attributes easily from inside the editor.

Solution 10 - Iphone

swift3

@IBDesignable
class BigTextField: UITextField {
    override func didMoveToWindow() {
        super.didMoveToWindow()
        if window != nil {
            borderStyle = .roundedRect
        }
    }
}

Interface Builder

  • Replace UITextField with BigTextField.
  • Change the Border Style to none.

Solution 11 - Iphone

My pathetic contribution to this dumb problem. In IB set the style to none so you can set the height, then in IB set the class to be a subclass of UITextField that forces the style to be rounded rect.

@interface JLTForcedRoundedRectTextField : UITextField
@end

@implementation JLTForcedRoundedRectTextField
- (void)awakeFromNib
{
    self.borderStyle = UITextBorderStyleRoundedRect;
}
@end

It kept me from having to hack the XIB file or writing style code into my view controller.

Solution 12 - Iphone

> A UITextField's height is not adjustable in Attributes Inspector only > when it has the default rounded corners border style, but adding a > height constraint (plus any other constraints which are required to > satisfy the autolayout system - often by simply using Add Missing > Constraints) to it and adjusting the constraint will adjust the > textfield's height. If you don't want constraints, the constraints can > be removed (Clear Constraints) and the textfield will remain at the > adjusted height.

Works like a charm.

Solution 13 - Iphone

In Swift 3 use:

yourTextField.frame.size.height = 30

Solution 14 - Iphone

try this

UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(20, 80, 280, 120)];

Solution 15 - Iphone

UITextField *txt = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    [txt setText:@"Ananth"];
    [self.view addSubview:txt];

Last two arguments are width and height, You can set as you wish...

Solution 16 - Iphone

You can use frame property of textfield to change frame Like-Textfield.frame=CGRECTMake(x axis,y axis,width,height)

Solution 17 - Iphone

This is quite simple.

yourtextfield.frame = CGRectMake (yourXAxis, yourYAxis, yourWidth, yourHeight);

Declare your textfield as a gloabal property & change its frame where ever you want to do it in your code.

Happy Coding!

Solution 18 - Iphone

If you're creating a lot of UITextFields it can be quicker to subclass UITextViews and override the setFrame method with

-(void)setFrame:(CGRect)frame{
    [self setBorderStyle:UITextBorderStyleRoundedRect];
    [super setFrame:frame];
    [self setBorderStyle:UITextBorderStyleNone];
}  

This way you can just call
[customTextField setFrame:<rect>];

Solution 19 - Iphone

I was having the same issue. tried some of the solutions here but rather than doing all this mumbo-jumbo. I found just setting height constraint is enough.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArunView Question on Stackoverflow
Solution 1 - IphoneBrianView Answer on Stackoverflow
Solution 2 - IphonenathanbroylesView Answer on Stackoverflow
Solution 3 - IphoneManjunathView Answer on Stackoverflow
Solution 4 - Iphoneuser1046037View Answer on Stackoverflow
Solution 5 - IphoneDavid SeekView Answer on Stackoverflow
Solution 6 - IphoneDeprecated DarrenView Answer on Stackoverflow
Solution 7 - IphoneSunil TargeView Answer on Stackoverflow
Solution 8 - IphoneGuillaume LaurentView Answer on Stackoverflow
Solution 9 - IphoneMark McCorkleView Answer on Stackoverflow
Solution 10 - IphoneneoneyeView Answer on Stackoverflow
Solution 11 - IphoneJeffery ThomasView Answer on Stackoverflow
Solution 12 - IphoneSimon.View Answer on Stackoverflow
Solution 13 - IphoneKaptainView Answer on Stackoverflow
Solution 14 - IphoneTendulkarView Answer on Stackoverflow
Solution 15 - IphoneUser-1070892View Answer on Stackoverflow
Solution 16 - IphoneHarshit_JobsView Answer on Stackoverflow
Solution 17 - IphoneVigneshView Answer on Stackoverflow
Solution 18 - IphonemylogonView Answer on Stackoverflow
Solution 19 - IphoneAlixView Answer on Stackoverflow