Search code examples
iosobjective-cuiviewcontrolleruisegmentedcontrol

hiding and adjusting of textfields based on view iOS


I am naive in iOS. I am developing a registration page which consists of hiding textfields based on views. In order to achieve this i implemented UISegmentedControl for views and used the following code for hiding the textfield based on segments

- (IBAction)regSegmentButton:(id)sender {

if (_registrationSegment.selectedSegmentIndex ==1) {
    self.vendorID.hidden = NO;
}
else {
    self.vendorID.hidden = YES;
}

}

Even though i achieved what i intended but the view is absurd. The view is represented below in images customerscreen vendorscreen

My question is how to make the view look normal even after hiding the field same as the way it is represented in "vendorscreen.png"(second image). Do i need to apply any animation in order to achieve it? if yes please let me know how to do it

Please do the needful..


Solution

  • You can do it with / without animation. Here is the step for without animation. You have to add your email-id, password, confirm password and register button to normal UIView as for eg: view1 then when you change the switch you have to adjust the 'y' position of view1. Like below

    - (IBAction)regSegmentButton:(id)sender {
    
        if (_registrationSegment.selectedSegmentIndex ==1) {
            self.vendorID.hidden = NO;
        }
        else {
            self.vendorID.hidden = YES;
        }
    
        int y = (_registrationSegment.selectedSegmentIndex == 1) ? 200 : 150
        CGRect rect = self.view1.frame;
        rect.origin.y = y;
        self.view1.frame = rect;
    }
    

    I've just hard coded the value for understanding, You need to adjust the y value based on your view.