Sarah Maher
Sarah Maher

Reputation: 830

Change the position dynamically

Im new to IOS development , so when i change the width of a UITextFeild dynamically i want the button below to shift up . i tried using the constrains but it doesn't seem to shift dynamically .

 (IBAction)selectStatus:(id)sender {
    CGRect frameRect = _textViewDevices.frame;
    frameRect.size.height = 10; 
    self.textViewDevices.frame = frameRect;

any good example of how to achieve that ?

I want to achieve something like the Relative positioning in android .

current box before any action on action the box size change

Upvotes: 0

Views: 78

Answers (2)

Viktor Simkó
Viktor Simkó

Reputation: 2637

Try calling layoutIfNeeded after the modifications:

- (IBAction)selectStatus:(id)sender {
    CGRect frameRect = _textViewDevices.frame;
    frameRect.size.height = 10; 
    self.textViewDevices.frame = frameRect;
    [self.view layoutIfNeeded];
}

If you have a height constraint on the text view, try to set its constant instead of setting the frame height:

- (IBAction)selectStatus:(id)sender {
    self.textViewHeightConstraint.constant = 10;
    [self.view layoutIfNeeded];
}

Upvotes: 2

ddb
ddb

Reputation: 2435

Programmatically when the first violet field changes in height, to make all the below views stay next to it, you should update the frame.origin.y properly.

So, for example, the status label should be reframed like this

CGRect frame = statusLabel.frame;
frame.origin.y = firstField.origin.y + firstField.size.height + 5;
statusLabel.frame = frame;

And the same for all below views (I've supposed 5 pixels of space between views)

Upvotes: 0

Related Questions