How to customize FBLoginVIew?

后端 未结 17 865
暗喜
暗喜 2020-12-02 05:56

In order to connect to facebook in my ios app i\'m using FBLoginVIew from Facebook SDK for iOS.

It shows a nice FB Login Button, but I want to use my own image and t

17条回答
  •  春和景丽
    2020-12-02 06:32

    The answer is to go over the FBLoginView subviews, find the button and the label and customize them.

    Here is the code:

    FBLoginView *loginview = 
    [[FBLoginView alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]];
    
    
    loginview.frame = CGRectMake(4, 95, 271, 37);
    for (id obj in loginview.subviews)
            {
                if ([obj isKindOfClass:[UIButton class]])
                {
                    UIButton * loginButton =  obj;
                    UIImage *loginImage = [UIImage imageNamed:@"YourImg.png"];
                    [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
                    [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
                    [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
                    [loginButton sizeToFit];
                }
                if ([obj isKindOfClass:[UILabel class]])
                {
                    UILabel * loginLabel =  obj;
                    loginLabel.text = @"Log in to facebook";
                    loginLabel.textAlignment = UITextAlignmentCenter;
                    loginLabel.frame = CGRectMake(0, 0, 271, 37);
                }
            }
    
    loginview.delegate = self;
    
    [self.view addSubview:loginview];
    

提交回复
热议问题