samedayloannocredit/credit-card-form-i-os

dev-master 2017-02-28 08:29 UTC

This package is not auto-updated.

Last update: 2024-09-18 20:04:34 UTC


README

同日贷款无信用检查

CI Status CocoaPods compatible Carthage compatible Swift 3 compatible Platform iOS License: MIT

CreditCardForm是一个iOS框架,允许开发者创建与实际信用卡相似的UI。

修复了拼写错误,使用CreditCardForm而不是CreditCardForum

截图

示例

要运行示例项目,首先克隆仓库,然后在Demo-*目录中运行pod install

支持的卡种

  • 万事达卡
  • 维萨卡
  • JCB
  • 大来卡
  • 发现卡
  • 美国运通卡

要求

  • Xcode 8
  • iOS 8.1+

安装

使用CocoaPods

CreditCardForm通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile

pod "CreditCardForm"

使用Carthage

CreditCardForm通过Carthage提供。要安装它,只需将以下行添加到您的Cartfile

github "orazz/CreditCardForm-iOS"

手动

如果您不希望使用上述任何依赖管理器,您可以将CreditCardForm手动集成到项目中。

  1. 下载并将CreditCardForm拖放到您的项目中。
  2. 完成!

使用示例

第一步:此框架与Stripe集成,您必须安装Stripe

Storyboard

创建一个视图,设置一个类CreditCardFormView(推荐框架大小:300x200)。
接下来,您将需要按照以下步骤进行一些简单的操作,以使一切正常运行。

import Stripe
import CreditCardForm

Swift

@IBOutlet weak var creditCardForm: CreditCardFormView!

// Stripe textField
let paymentTextField = STPPaymentCardTextField()

在您的视图控制器中viewDidLoad函数中添加以下代码

// Set up stripe textfield
paymentTextField.frame = CGRect(x: 15, y: 199, width: self.view.frame.size.width - 30, height: 44)
paymentTextField.translatesAutoresizingMaskIntoConstraints = false
paymentTextField.borderWidth = 0

let border = CALayer()
let width = CGFloat(1.0)
border.borderColor = UIColor.darkGray.cgColor
border.frame = CGRect(x: 0, y: paymentTextField.frame.size.height - width, width:  paymentTextField.frame.size.width, height: paymentTextField.frame.size.height)
border.borderWidth = width
paymentTextField.layer.addSublayer(border)
paymentTextField.layer.masksToBounds = true

view.addSubview(paymentTextField)

NSLayoutConstraint.activate([
paymentTextField.topAnchor.constraint(equalTo: creditCardForm.bottomAnchor, constant: 20),
paymentTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor),
paymentTextField.widthAnchor.constraint(equalToConstant: self.view.frame.size.width-20),
paymentTextField.heightAnchor.constraint(equalToConstant: 44)
])

委托方法

为了使用委托方法,首先在设置时将Stripe的委托设置为父视图控制器

paymentTextField.delegate = self

之后,您将能够在父视图控制器中设置以下委托方法

func paymentCardTextFieldDidChange(_ textField: STPPaymentCardTextField) {
creditCardForm.paymentCardTextFieldDidChange(cardNumber: textField.cardNumber, expirationYear: textField.expirationYear, expirationMonth: textField.expirationYear, cvc: textField.cvc)
}

func paymentCardTextFieldDidEndEditingExpiration(_ textField: STPPaymentCardTextField) {
creditCardForm.paymentCardTextFieldDidEndEditingExpiration(expirationYear: textField.expirationYear)
}

func paymentCardTextFieldDidBeginEditingCVC(_ textField: STPPaymentCardTextField) {
creditCardForm.paymentCardTextFieldDidBeginEditingCVC()
}

func paymentCardTextFieldDidEndEditingCVC(_ textField: STPPaymentCardTextField) {
creditCardForm.paymentCardTextFieldDidEndEditingCVC()
}

现在您应该准备好使用CreditCardForm了!!

自定义

1) 颜色

creditCardForm.backgroundColor (UIColor)
creditCardForm.cardHolderExpireDateColor (UIColor)
creditCardForm.cardHolderExpireDateTextColor (UIColor)
creditCardForm.backLineColor (UIColor)

// Brands Color brand name, front color, back color
[String: [UIColor]]
creditCardForm.colors[Brands.Visa.rawValue] = [UIColor.black, UIColor.black]
...
creditCardForm.colors[Brands.MasterCard.rawValue] = [UIColor.black, UIColor.black]

2) 图片

creditCardForm.chipImage (UIImage)

3) 占位符

creditCardForm.cardHolderString (String)
creditCardForm.expireDatePlaceholderText (String)

卡号:配置掩码字段

creditCardForm.cardNumberMaskExpression (String)
creditCardForm.cardNumberMaskTemplate (String)

creditCardForm.cardNumberFontSize (CGFloat)

贡献

我们非常希望您为CreditCardForm做出贡献,请查看LICENSE文件以获取更多信息。

元信息

Oraz Atakishiorazz.tm@gmail.com

第三方库

CreditCardValidator
AKMaskField

许可协议

CreditCardForm可在MIT许可下获得。有关更多信息,请参阅LICENSE文件。