Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I customize Login button of Twitter kit in iOS?

I have downloaded a Twitter kit framework and added code to login with Twitter. But, I don't want Login button look like that. I want a custom button for Login. Can I do that ? I only want to use this framework as this also leverages with iOS system account.

like image 761
NSPratik Avatar asked May 18 '15 11:05

NSPratik


3 Answers

As per the document :

Add the code in your button press :

Objective-C

[[Twitter sharedInstance] logInWithCompletion:^
            (TWTRSession *session, NSError *error) {
  if (session) {
      NSLog(@"signed in as %@", [session userName]);
  } else {
      NSLog(@"error: %@", [error localizedDescription]);
  }
}];

Swift

Twitter.sharedInstance().logInWithCompletion {
                (session, error) -> Void in
    if (session != nil) {
        println("signed in as \(session.userName)");
    } else {
        println("error: \(error.localizedDescription)");
    }
}
like image 150
Ashish Kakkad Avatar answered Nov 06 '22 19:11

Ashish Kakkad


Yes,you can do customize your Twitter login button.

Just add your UIButton in your storyboard's desired View controller. Select it and open the identity inspector, now in the Class textfield, enter "TWTRLogInButton" after that create a property.

You will create something like this:-

@property (nonatomic,strong) IBOutlet TWTRLogInButton *customTwitterButton;

After that you can use it or implement it in your viewDidLoad method like this:-

self.customTwitterButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
    // do operations as per your wish
}];
like image 30
Vizllx Avatar answered Nov 06 '22 20:11

Vizllx


Twitter has provided a separate method for Sign In in the documentation. Create your custom button in xib or storyboard, give it a selector and add a method for twitter login. Here is an example:

- (IBAction)btnTwitterLogin_pressed:(id)sender
{
    [[Twitter sharedInstance] logInWithCompletion:^
     (TWTRSession *session, NSError *error) {
         if (session) {
             NSLog(@"%@", [session userID]);
             NSLog(@"%@", [session userName]);
             NSLog(@"%@", [session authToken]);
             NSLog(@"%@", [session authTokenSecret]);
         } else {
             NSLog(@"Error: %@", [error localizedDescription]);
         }
     }];
}

Hope it helps others too.

like image 21
NSPratik Avatar answered Nov 06 '22 21:11

NSPratik