Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

white or light ASAuthorizationAppleIDButton "Sign in with Apple" button - Swift

Tags:

ios

swift

I am implementing ASAuthorizationAppleIDButton - as per Apple's request - but unfortunately my login background is dark and I can't find how to change the button color to a light or white button like the ones Apple show in many of their examples?

This is what I have:

let appleButton = ASAuthorizationAppleIDButton()

override func viewDidLoad() {
    super.viewDidLoad()       
    setAppleButtonStyle()
}

func setAppleButtonStyle() {
    if #available(iOS 13.0, *) {
        appleButton.translatesAutoresizingMaskIntoConstraints = false

        view.addSubview(appleButton)
        NSLayoutConstraint.activate([
            appleButton.centerYAnchor.constraint(equalTo: facebookLoginView.centerYAnchor, constant: -70),
            appleButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
            appleButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
            appleButton.heightAnchor.constraint(equalToConstant: 50)
        ])
    } else {
        //Do Nothing
    }

}
like image 882
Brewski Avatar asked Dec 02 '22 09:12

Brewski


2 Answers

Simply provide the desired style when you instantiate the button instance.

E.g.

let appleButton = ASAuthorizationAppleIDButton(type: .default, style: .white)
like image 52
Paulw11 Avatar answered May 24 '23 03:05

Paulw11


This would be what you would use if you were using Objective-C:

 ASAuthorizationAppleIDButton *appleIDButton = [ASAuthorizationAppleIDButton buttonWithType:ASAuthorizationAppleIDButtonTypeContinue style:ASAuthorizationAppleIDButtonStyleBlack];
like image 20
Ramsheer T Avatar answered May 24 '23 03:05

Ramsheer T