Add button in PFLogInViewController

234 Views Asked by At

Hi Can we add a additional button when creating a custom view. I created a subclass for PFLogInViewController. The button was added but i cannot clicked the button. Is it allowed to add additional button in PFLogInViewController child class?

Thanks!

1

There are 1 best solutions below

0
euvs On

To add a button (or any other view) you need to subclass PFLogInViewController as described in this tutorial https://parse.com/tutorials/login-and-signup-views

For example, if you wish to add 1Password button to the Parse login view's password field, you can do it like this:

@interface MyParseLogInViewController : PFLogInViewController

@end

@implementation MyParseLogInViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Add 1Password button
    UIButton *btn1Password = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1Password addTarget:self action:@selector(onePasswordButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
    [btn1Password setImage:[UIImage imageNamed:@"onepassword-button"] forState:UIControlStateNormal];
    [self.logInView.passwordField addSubview:btn1Password];

    // Add constraints to align it to the right.
    btn1Password.translatesAutoresizingMaskIntoConstraints = NO;
    [self.logInView addConstraint:[NSLayoutConstraint constraintWithItem: btn1Password
                                                               attribute: NSLayoutAttributeCenterY
                                                               relatedBy: NSLayoutRelationEqual
                                                                  toItem: self.logInView.passwordField
                                                               attribute: NSLayoutAttributeCenterY
                                                              multiplier: 1.0
                                                                constant: 0.0]];
    [self.logInView addConstraint:[NSLayoutConstraint constraintWithItem: btn1Password
                                                               attribute: NSLayoutAttributeTrailing
                                                               relatedBy: NSLayoutRelationEqual
                                                                  toItem: self.logInView.passwordField
                                                               attribute: NSLayoutAttributeTrailing
                                                              multiplier: 1.0
                                                                constant: -5.0]];
    [self.logInView addConstraint:[NSLayoutConstraint constraintWithItem: btn1Password
                                                               attribute: NSLayoutAttributeWidth
                                                               relatedBy: NSLayoutRelationEqual
                                                                  toItem: nil
                                                               attribute: NSLayoutAttributeNotAnAttribute
                                                              multiplier: 1.0
                                                                constant: 48.0]];
    [self.logInView addConstraint:[NSLayoutConstraint constraintWithItem: btn1Password
                                                               attribute: NSLayoutAttributeHeight
                                                               relatedBy: NSLayoutRelationEqual
                                                                  toItem: nil
                                                               attribute: NSLayoutAttributeNotAnAttribute
                                                              multiplier: 1.0
                                                                constant: 32.0]];
}

- (void)onePasswordButtonTapped:(id)sender
{
    NSLog(@"Button tapped");
}