How does one custom resize the iOS login button

ios
oauth
login

#1

I’m having so much trouble getting the login button to resize. I’ve tried to create a frame with CGRect, like so(within viewDidLoad)

let twitterLoginButton = TWTRLogInButton(frame: CGRectMake(0, 0, 200, 50))
self.view.addSubview(twitterLoginButton)

Also tried this

let twitterLoginButton = TWTRLogInButton.init(frame: CGRectMake(0, 0, 200, 50))
self.view.addSubview(twitterLoginButton)

But no luck.

Also tried to force the button into a parent container and then try to force the button to assume the size of parent like so

let twitterLoginButton = TWTRLogInButton()
let twitterLoginButtonParent = TWTRLogInButton(frame: CGRectMake(0, 0, 200, 50))
twitterLoginButtonParent.addSubview(twitterLoginButton)
self.view.addSubview(twitterLoginButtonParent)

let twitterLoginButtonSize = CGSize(width: 200, height: 50)
twitterLoginButton.sizeThatFits(twitterLoginButtonSize)

Is it even possible to resize this button? Supposedly it is a subclass of UIButton, yet none of the methods of UIButton seem to work on it. Thanks.


#2

Hey @RelevantMe

One quick question - do you have AutoLayout set to “Yes” in a Xib file or Storyboard? That would be preventing your changes from taking effect. With AutoLayout set to “No”, I’m able to get this to display (I made it look bad intentionally :)) :

Using: (Obj-C, instead of Swift, but both should work)

    logInButton.center = self.view.center;
    [logInButton setFrame:CGRectMake(273, 269, 130, 144)];
    [self.view addSubview:logInButton];

#3

@bonnell Thanks for the response. Unfortunately though, disabling auto layout for the UI in question did not work. The button still stubbornly won’t adhere to any CGRect specifications :frowning:


#4

@bonnell Finally got it to work:) by first initializing the button with loginCompletion before assigning it a frame.

    let twitterLoginButton = TWTRLogInButton(logInCompletion: { session, error in
        if (session != nil) {
            print("signed in as \(session!.userName)");
        } else {
            print("error: \(error!.localizedDescription)");
        }
    })

    twitterLoginButton.frame  = CGRectMake(0, 0, 50, 50)

#5

Thanks for sharing your solution @RelevantMe and happy coding!