asportnoy
asportnoy

Reputation: 2534

How to add "Add to Apple Wallet" button with PKAddPassButton - swift

Sorry if this sounds dumb, complete swift noob here,

I'm trying to create the "Add to Apple Wallet" button. But I can't figure out how. I've tried the code snippet here, but nothing showed up on my screen in the simulator. My current code:

import UIKit
import PassKit


class ViewController: UIViewController {

    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        addWalletButton()

    }

    private func addWalletButton() {
        let passButton =  PKAddPassButton(addPassButtonStyle: PKAddPassButtonStyle.black)
        passButton.center = view.center
        view.addSubview(passButton)
    }

}

Any suggestions? Thanks.

Upvotes: 4

Views: 9248

Answers (1)

PassKit
PassKit

Reputation: 12591

Looks like your button has no bounds.

Try:

let passButton = PKAddPassButton(addPassButtonStyle: PKAddPassButtonStyle.black)
passButton.frame = CGRect(x:  (UIScreen.main.bounds.width-280)/2, y: 150, width: 280, height: 60)
passButton.addTarget(self, action: #selector(passButtonAction), for: .touchUpInside)
view.addSubview(passButton)

Adjust the size and position to suit your app. And don't forget to add an action so it does something when tapped.

Upvotes: 5

Related Questions