OPApplePayButton
@objc
public class OPApplePayButton : UIControl
Convenience control that wraps Apple’s PKPaymentButton
It is possible to use Apple’s PKPaymentButton
instead of this class if desired. This control provides all styling and customization options provided by
PKPaymentButton
but also adds some extra functionality:
- Optional use of
onClick
property for simpler handling of touch events (UIControl.addTarget(...)
is also supported) Ability to update button visuals after view creation (see
updateButton
)Important
The default height of this view matches the intrinsic height ofPKPaymentButton
. If constraints or other factors cause this view’s height to expand beyond the intrinsic size, thePKPaymentButton
will be centered vertically within this view.
-
Initializes this control with default values of
PKPaymentButtonStyle.black
,PKPaymentButtonType.checkout
and a corner radius of 8Declaration
Swift
public convenience init()
-
Initializes this control with default values of
PKPaymentButtonStyle.black
,PKPaymentButtonType.checkout
and a corner radius of 8Declaration
Swift
public override init(frame: CGRect)
Parameters
frame
The frame to use for this control
-
Inititalizes this control with the given type, style, and corner radius
Declaration
Swift
@objc public convenience init( type: PKPaymentButtonType, style: PKPaymentButtonStyle, cornerRadius: CGFloat )
Parameters
type
The type of button to display
style
The style to use for the button
cornerRadius
The corner radius of the button
-
Inititalizes this control with the given frame, type, style, and corner radius
Declaration
Swift
@objc public init( frame: CGRect, type: PKPaymentButtonType, style: PKPaymentButtonStyle, cornerRadius: CGFloat )
Parameters
frame
The frame to use for this control
type
The type of button to display
style
The style to use for the button
cornerRadius
The corner radius of the button
-
Click handler to handle click events. It is also possible to handle click events using
UIControl.addTarget(...)
Declaration
Swift
@objc public var onClick: (() -> Void)?
-
Whether or not the button is enabled
Declaration
Swift
public override var isEnabled: Bool { get set }
-
Whether or not user events are enabled or ignored and removed from the event queue
Declaration
Swift
public override var isUserInteractionEnabled: Bool { get set }
-
Whether or not the button is highlighted
Declaration
Swift
public override var isHighlighted: Bool { get set }
-
Updates the button with the given type, style, and corner radius
Important
Because Apple does not provide a way to update the button type or style after creation, this method removes the currentPKPaymentButton
instance from this view and then creates and attaches a new instance. If only the corner radius needs to be udpated useupdateCornerRadius(...)
because that does not require the underlying button to be recreated.Declaration
Swift
@objc public func updateButton( type: PKPaymentButtonType, style: PKPaymentButtonStyle, cornerRadius: CGFloat )
-
Updates the corner radius of the button
Declaration
Swift
@objc public func updateCornerRadius(cornerRadius: CGFloat)