nonuma
nonuma

Reputation: 399

UITextField doesn't take whole screen width

I'm using a UITextField and a UIButton as you can see in this screenshot:

enter image description here

Sometimes the "test" button needs to be disabled so I disable it with this code:

    [_hButton setEnabled:NO];
    [_hButton setHidden: true]; 

But the problem is that the UITextField doesn't take the whole width from the screen like you can see here:

enter image description here

This are the settings from the UITextField in my storyboard:

enter image description here

Any idea how I can fix this?

Upvotes: 0

Views: 223

Answers (3)

Jeepston
Jeepston

Reputation: 1359

UITextView is not resizing since the button is still there, it's just not visible. After you hide the button, adjust UItextView frame manually.

Upvotes: 0

Mani
Mani

Reputation: 17585

When you doing this [_hButton setEnabled:NO]; [_hButton setHidden: true];, you have to modify textField width.

Your code should be..

CGRect oldFrame = yourTextField.frame;
CGRect frameNew = CGRectMake(oldFrame.origin.x,oldFrame.origin.y,oldFrame.size.width + _hbutton.frame.size.width,oldFrame.size.height);
yourTexField.frame = frameNew;

When you want back this, just do reverse calculation.

Upvotes: 4

Dobroćudni Tapir
Dobroćudni Tapir

Reputation: 3102

Although the button isHidden, it is still there. You should remove it from the view completely for the desired effect [_hButton removeFromSuperview];

Upvotes: 0

Related Questions