Reputation: 399
I'm using a UITextField and a UIButton as you can see in this screenshot:
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:
This are the settings from the UITextField in my storyboard:
Any idea how I can fix this?
Upvotes: 0
Views: 223
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
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
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