Добавить кнопку в PFLogInViewController

Привет. Можем ли мы добавить дополнительную кнопку при создании пользовательского представления. Я создал подкласс для PFLogInViewController. Кнопка была добавлена, но я не могу нажать кнопку. Можно ли добавить дополнительную кнопку в дочерний класс PFLogInViewController?

Спасибо!


person zuil7    schedule 30.07.2014    source источник


Ответы (1)


Чтобы добавить кнопку (или любое другое представление), вам необходимо создать подкласс PFLogInViewController, как описано в этом руководстве https://parse.com/tutorials/login-and-signup-views

Например, если вы хотите добавить кнопку 1Password в поле пароля представления входа в систему Parse, вы можете сделать это следующим образом:

@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");
}
person euvs    schedule 16.11.2014