在PFLogInViewController中添加按钮

时间:2014-07-30 10:23:21

标签: parsing pfloginviewcontroller

您好我们可以在创建自定义视图时添加其他按钮。我为PFLogInViewController创建了一个子类。按钮已添加,但我无法单击该按钮。是否允许在PFLogInViewController子类中添加其他按钮?

谢谢!

1 个答案:

答案 0 :(得分:1)

要添加按钮(或任何其他视图),您需要按照本教程https://parse.com/tutorials/login-and-signup-views

中的描述继承PFLogInViewController

例如,如果您希望将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");
}