0

I am working on a project where I am using custom buttons for login and signup. All I want is when I click on login, the color of signup button changes and when I click on signup button again the color of login button changs back.

I tried the following code:

 - (void)viewDidLoad
   {
       [super viewDidLoad];
       // [self.view setNuiClass:@"ViewInit"];
        // Do any additional setup after loading the view from its nib.
        UIImageView *img = [[UIImageView alloc ] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        img.image = [UIImage imageNamed:@"iphone-4-apple-logo-wallpapers-set-2-05.jpg"];
        [self.view addSubview:img];
        NSLog(@"Height Pro %f",[[DeviceClass instance] getResizeScreen:NO].size.height);
        scrollView = [[UIScrollView alloc] initWithFrame:[[DeviceClass instance] getResizeScreen:NO]];
        scrollView.alwaysBounceVertical = YES;
        scrollView.delegate = self;
        [self.view addSubview:scrollView];


        segmentControl = [[UISegmentedControl alloc] initWithItems:@[NSLocalizedString(@"profile_tab_signin", nil),NSLocalizedString(@"profile_tab_signup", nil)]];
        segmentControl.frame = CGRectMake(10, 10, 300, 40);
        segmentControl.selectedSegmentIndex = 0;
        [segmentControl addTarget:self action:@selector(valueChanged) forControlEvents: UIControlEventValueChanged];

        [scrollView addSubview:segmentControl];

        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [self.view addGestureRecognizer:singleTap];

        //Init
        [self autoLogin];
        [self.view setNeedsDisplay];


        //[signUpBtn setBackgroundColor:[UIColor redColor]];
        //[loginBtn setBackgroundColor:[UIColor yellowColor]];
    }


  - (void)valueChanged
    {

        //For SignIn/SignUp

        if(segmentControl.selectedSegmentIndex == 0)
        {

            [usernameSignUp removeFromSuperview];
            [emailSignUp removeFromSuperview];
            [firstNameSignUp removeFromSuperview];
            [lastNameSignUp removeFromSuperview];
            [passwordSignUp removeFromSuperview];
            [retypepasswordSignUp removeFromSuperview];
            [signUpBtn removeFromSuperview];

            //[signUpBtn setBackgroundColor:[UIColor redColor]];
            [self signInForm];
        }

        else
        {
             [lostPassword removeFromSuperview];
            [username removeFromSuperview];
            [password removeFromSuperview];
            [loginBtn removeFromSuperview];
            [self signUpForm];

        }
    }

Please suggest me some useful code as I am new in iOS.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
iAbhi
  • 1
  • 2

0 Answers0