I've got an UITextField
and I intend to programmatically add an UIButton
to its right side when user touches the TextField
and brings up the keyboard.
------------------------------
|--------------------------- |
|| textfield | |
|--------------------------- |
------------------------------
when keyboard is been brought up:
------------------------------
|------------------ |
|| textfield | BUTTON |
|------------------ |
------------------------------
I use Storyboard
with AutoLayout for interface building and these elements are all well connected.
When I was trying to change the width of the UITextField
, it didn't change at all, resulting the Button
was put "inside" the textfield, like the screenshot shown below:
Here's my code:
// code to add the button
- (void)keyboardWasShown:(NSNotification*)aNotification
{
// dynamically add a "reply" button
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.replyViewBox addSubview:button];
[button setTitle:@"Reply" forState:UIControlStateNormal];
// change button size & position
button.frame = CGRectMake(265.0, 10.0, 46.0, 30.0);
// [button sizeToFit];
// change replyText size
CGRect frameRct = replyText.frame;
frameRct.size.width = 248.0;
replyText.frame = frameRct;
[replyViewBox addSubview:button];
}
I've set the constraints via Storyboard, so is there anyway to let me change the width programmatically whilst maintaining the AutoLayout?