效果圖:

效果圖
在iOS8之前,iOS系統(tǒng)的輸入法只能使用蘋果官方提供的輸入法。
對(duì)于中文來說,官方的輸入法并不好用,或者說不夠好用,詞庫,聯(lián)想,云輸入等都沒有或者和搜狗輸入法,百度輸入法等有中國(guó)特色的輸入法相比有一定的差距。
部分用戶因?yàn)檩斎敕ǖ脑?,選擇了安卓等其他系統(tǒng),或者選擇了越獄。
iOS自定義鍵盤是iOS8系統(tǒng)新推出的功能,允許開發(fā)者開發(fā)第三方鍵盤。
眾人拾柴火焰高,功能的開放,為iOS用戶體驗(yàn)的提示必然帶來更大的推動(dòng)。
系統(tǒng)默認(rèn)的鍵盤其中有滿足要求的數(shù)字鍵盤。
但是為了滿足視覺效果更美觀,根據(jù)具功能需求,寫了這個(gè)自定義收款鍵盤。該鍵盤支持整數(shù)最大6位數(shù),小數(shù)點(diǎn)后2位數(shù)。下面介紹使用方法:
1.獲取代碼
源碼地址(GitHub)
去GitHub下載源碼,記得點(diǎn)顆星喲?。?!

項(xiàng)目文件截圖
將KeyboardView.h、KeyboardView.m文件添加到項(xiàng)目中。
2.KeyboardView的使用
在ViewController中添加下面代碼:
#import "ViewController.h"
#import "KeyboardView.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@property(strong,nonatomic)KeyboardView *keyboardView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightTextColor];
}
- (void)viewWillAppear:(BOOL)animated {
//使用KeyboardView類
self.keyboardView = [[KeyboardView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
[self.view addSubview:_keyboardView];
[self.keyboardView showPopView];
[self.keyboardView.myBtn1 addTarget:self action:@selector(myBtn1:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)myBtn1:(UIButton *)sender {
NSLog(@"點(diǎn)擊了收款按鈕");
}
OK,到這里就可以使用自定義的收款鍵盤了。
KeyboardView內(nèi)部代碼詳解
- KeyboardView.h
//
// KeyboardView.h
// 自定義金額鍵盤
//
// Created by fby on 2017/9/22.
// Copyright ? 2017年 TextDemo. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface KeyboardView : UIView
//收款按鈕,在ViewController中獲取點(diǎn)擊事件
@property(strong,nonatomic)UIButton *myBtn1;
//如果需要根據(jù)輸入金額,來限制首款按鈕,可使用moneyLab
@property(strong,nonatomic)UILabel *moneyLab;
//視圖顯示
-(void)showPopView;
@end