iosswiftpasskit

PKAddPassButton text and icon too large


When I add the PKAddPassButton to any project, the text and the icon look unnaturally large. The designers on my team feel sick looking at it and I don't blame them. To prove a point I created a blank project and this is how the button looks:

enter image description here

If you compare it to Apple examples (page 3 here https://developer.apple.com/wallet/Add-to-Apple-Wallet-Guidelines.pdf) the text is significantly small.

The code is very minimal. I have a button on a storyboard from which I take a frame for my PKAddPassButton.

import UIKit
import PassKit

class ViewController: UIViewController {

    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        let pkButton = PKAddPassButton()
        view.addSubview(pkButton)
        pkButton.frame = button.frame
        button.isHidden = true
    }
}

Solution

  • It's odd that the sizing is so wrong to start with. I verified that changing the frame of the button does not resize the label or the icon.

    Probably the best option would be to apply a scale transform to the button. This would work:

    let scale = CGFloat(floatLiteral: 0.75)
    pkButton.transform = CGAffineTransform(scaleX: scale, y: scale)
    

    I don't necessarily recommend this, but I did verify that you can adjust the font size manually:

    let label = pkButton.value(forKey: "singleLineLabel")! as! UILabel
    let label2 = pkButton.value(forKey: "multiLineLabel")! as! UILabel
    label.font = UIFont(name: label.font.fontName, size: 8)
    label2.font = UIFont(name: label2.font.fontName, size: 8)
    

    I haven't tried the icon, but I suspect you can do something similar.