SimpleSwiftNumericKeyboard 0.1.4

SimpleSwiftNumericKeyboard 0.1.4

Miguel Machado 维护。



  • 作者
  • mmachado53

SimpleSwiftNumericKeyboard

CI Status Version License Platform

它是 iPad 上的一个简单数字键盘。

preview

示例

要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install

所需条件

安装

SimpleSwiftNumericKeyboard 可通过 CocoaPods 获得。要安装它,只需在您的 Podfile 中添加以下行

pod 'SimpleSwiftNumericKeyboard'

作者

mmachado53, [email protected]

在故事板的用法

在可检查变量 keyboardNumericType 中设置值,可以是

  • ####"numeric"
    禁用"."和"-"键
  • ####"decimal"
    启用"."键,禁用"-"键
  • ####"decimalnegative"
    启用"."和"-"键
  • ####"numericnegative"
    禁用"."键,启用"-"键

storyboard usage

在代码中的用法

只需使用 "NumericKeyBoard.set" 函数

import SimpleSwiftNumericKeyboard

override func viewDidLoad() {
        super.viewDidLoad()
        // type can be: .decimalPad .decimalNegativePad .numberPad .numberNegativePad
        NumericKeyBoard.set(uiTextFieldInstance, type: .numberPad) 
        
    }

自定义颜色

基本上有两种按钮类型,"数字按钮"和"辅助按钮" 按钮类型

全局颜色自定义

需要在 AppDelegate 中进行配置

// AppDelegate.swift

import SimpleSwiftNumericKeyboard

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    
    /* 
        NumericKeyBoard.GLOBAL_COLOR_PALETTE is a [NumericKeyBoardColorPaletteProp : UIColor]
    */
    
    // Color of background 
    NumericKeyBoard.GLOBAL_COLOR_PALETTE[.backgroundColor] = UIColor.black
    
    // Color of numbers buttons 
    NumericKeyBoard.GLOBAL_COLOR_PALETTE[.stateNormalNumberButton] = UIColor.black
    
    // Color of number buttons when is pressed
    NumericKeyBoard.GLOBAL_COLOR_PALETTE[.statePressNumerButton] = UIColor.white.withAlphaComponent(0.3)
   
    // Color of text in numbers buttons
    NumericKeyBoard.GLOBAL_COLOR_PALETTE[.textColorNumberButton] = UIColor.white
   
    // Color of secondary buttons     
    NumericKeyBoard.GLOBAL_COLOR_PALETTE[.stateNormalSecondaryButton] = UIColor(red: 0.18, green: 0.18, blue: 0.18, alpha: 1)
   
    // Color of secondary buttons when is pressed
    NumericKeyBoard.GLOBAL_COLOR_PALETTE[.statePressSecondaryButton] = UIColor.white.withAlphaComponent(0.3)
   
    // Color of text in secondary buttons      
    NumericKeyBoard.GLOBAL_COLOR_PALETTE[.textColorSecondaryButton] = UIColor.white
    
    return true
}

在特定 UiTextField 中的颜色自定义

import SimpleSwiftNumericKeyboard

override func viewDidLoad() {
        super.viewDidLoad()
        
        var redStyle:[NumericKeyBoardColorPaletteProp:UIColor] = [:]
        redStyle[.backgroundColor] = UIColor(red: 0.85, green: 0, blue: 0.21, alpha: 1.0)
        redStyle[.stateNormalNumberButton] = UIColor(red: 1.0, green: 0, blue: 0.21, alpha: 1.0)
        redStyle[.statePressNumerButton] = UIColor.white.withAlphaComponent(0.3)
        redStyle[.textColorNumberButton] = UIColor.white
        redStyle[.stateNormalSecondaryButton] = UIColor(red: 0.75, green: 28 / 255, blue: 70 / 255, alpha: 1.0)
        redStyle[.statePressSecondaryButton] = UIColor.white.withAlphaComponent(0.3)
        redStyle[.textColorSecondaryButton] = UIColor.white
        // type can be: .decimalPad .decimalNegativePad .numberPad .numberNegativePad
        NumericKeyBoard.set(tf, type: .numberNegativePad,customPalette: redStyle)
        
    }

许可证

SimpleSwiftNumericKeyboard 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。