如何仅设置苹果标志图像以使用苹果按钮登录

How to set only apple logo image to sign in with apple button

我正在开发一个应用程序,我在其中提供了三个登录选项,例如 facebook、google 和 apple。我需要为所有三个设置相同的设计。我的苹果登录按钮是矩形的,我想知道我能否更改该按钮的设计以及如何更改。我需要使它只带有苹果标志而不是文字的圆形。那么如何将苹果徽标图像设置为 ASAuthorizationAppleIDButton。我在 link 上阅读了有关苹果设计的内容,但没有提及如何将图像设置为按钮。 https://developer.apple.com/design/human-interface-guidelines/apple-pay/overview/buttons-and-marks/

您需要按照 Apple Human Interface Guideline 制作自定义按钮。您必须遵循他们的指南以避免评论被拒绝。

您可以从here

下载苹果设计资源

要在应用中添加自定义按钮:

func appleCustomLoginButton() {
   //Sign in with app is only available from iOS 13 onwards
    if #available(iOS 13.0, *) {
        let customAppleLoginBtn = UIButton()
        customAppleLoginBtn.backgroundColor = UIColor.white
        customAppleLoginBtn.setImage(UIImage(named: "appleLogo"), for: .normal)
        customAppleLoginBtn.addTarget(self, action: #selector(actionHandleAppleSignin), for: .touchUpInside)
        view.addSubview(customAppleLoginBtn)

        // Setup Layout Constraints to be in the center of the screen
        customAppleLoginBtn.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            customAppleLoginBtn.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
            customAppleLoginBtn.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
            customAppleLoginBtn.widthAnchor.constraint(equalToConstant: 200),
            customAppleLoginBtn.heightAnchor.constraint(equalToConstant: 40)
            ])
    }
}

@objc func actionHandleAppleSignin() {

    //do something when button is clicked
}

很简单。如果您有任何进一步的疑问,请随时询问,谢谢。

     //1. setting apple logo
        let appleLogo = UIImage(systemName: "appleLogo.png")!
     //2. create a button
        let button = UIButton()
     //3. setImage with image name
        button.setImage(appleLogo, for: .normal)
     //4. Set image rounded.
        button.layer.cornerRadius = button.frame.height/2
     //5. Setting empty button text
        button.titleLabel?.text = ""