• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

orazz/CreditCardForm-iOS: CreditCardForm is iOS framework that allows developers ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

orazz/CreditCardForm-iOS

开源软件地址:

https://github.com/orazz/CreditCardForm-iOS

开源编程语言:

Swift 97.7%

开源软件介绍:

CreditCardForm

CI Status CocoaPods compatible Carthage compatible Swift 4.2 compatible Platform iOS License: MIT Donate

CreditCardForm is iOS framework that allows developers to create the UI which replicates an actual Credit Card.

Fixed typo use CreditCardForm instead CreditCardForum

Screenshots

Example

To run the example project, clone the repo, and run pod install from the Demo-* directory first.

Supported Cards

  • MasterCard
  • Visa
  • JCB
  • Diners
  • Discover
  • Amex
  • UnionPay

Requirements

  • Xcode 8
  • iOS 8.1+

Installation

Using CocoaPods

CreditCardForm is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CreditCardForm"

Using Carthage

CreditCardForm is available through Carthage. To install it, simply add the following line to your Cartfile:

github "orazz/CreditCardForm-iOS"

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate CreditCardForm into your project manually.

  1. Download and drop CreditCardForm in your project.
  2. Done!

Usage example

First step: this framework integrated with Stripe, you must install Stripe

Storyboard

Create a view set a class CreditCardFormView (preferred frame size: 300x200).
Following this you will have to go through a few simple steps outlined below in order to get everything up and running.

import Stripe
import CreditCardForm

Swift

@IBOutlet weak var creditCardForm: CreditCardFormView!

// Stripe textField
let paymentTextField = STPPaymentCardTextField()

Add the following code in the viewDidLoad function in your view controller

// 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)
])

Delegate Methods

In order to use the delegate methods first set the delegate of Stripe to the parent view controller when setting it up

paymentTextField.delegate = self

After that you will be able to set up the following delegate methods inside of your parent view controller

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

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

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

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

You should now be ready to use CreditCardForm!!

Customization

1) Colors

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

// Brands Color brand name, front color, back color
[String: [UIColor]]

creditCardForm.cardGradientColors[Brands.Visa.rawValue] = [UIColor.blue, UIColor.red]

// Set font
creditCardForm.cardNumberFont = UIFont(name: "FontName", size: 20)!
creditCardForm.cardPlaceholdersFont = UIFont(name: "FontName", size: 10)!
creditCardForm.cardTextFont = UIFont(name: "FontName", size: 12)!

2) Images

creditCardForm.chipImage (UIImage)

3) Placeholders

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

Card number: Configuring the Mask Field

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

creditCardForm.cardNumberFontSize (CGFloat)

Contribute

We would love for you to contribute to CreditCardForm, check the LICENSE file for more info.

Meta

Oraz Atakishiyev, orazz.com

3rd party libraries

CreditCardValidator
AKMaskField

License

CreditCardForm is available under the MIT license. See the LICENSE file for more info.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap