细分控件背景颜色未被更改

时间:2015-08-19 11:09:07

标签: ios cocoa-touch uibutton

我正在开发一个项目,我使用自定义按钮进行登录和注册。 我想要的只是当我点击登录时,注册按钮的颜色会发生变化,当我再次点击注册按钮时,登录按钮的颜色会变回。

我尝试了以下代码:

 - (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];

        }
    }

请告诉我一些有用的代码,因为我是iOS新手。

0 个答案:

没有答案