本文实例为大家分享了ios自定义键盘切换的相关代码,供大家参考,具体内容如下
具体代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
- ( void )viewdidload { [super viewdidload]; // do any additional setup after loading the view, typically from a nib. self.title = @ "小飞哥键盘" ; self.textfield = [[uitextfield alloc] initwithframe:cgrectmake(50, 168, kscreenwidth - 100, 50)]; self.textfield.delegate = self; self.textfield.backgroundcolor = [uicolor greencolor]; self.textfield.placeholder = @ "(默认系统键盘)" ; [self.view addsubview:self.textfield]; uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(hidenkeyboard)]; [self.view addgesturerecognizer:tap]; uisegmentedcontrol *segment = [[uisegmentedcontrol alloc] initwithitems:@[@ "键盘1" ,@ "键盘2" ,@ "键盘3" ,@ "系统键盘" ]]; segment.frame = cgrectmake(0, 100, kscreenwidth, 50); [segment addtarget:self action:@selector(keyboardtypeaction:) forcontrolevents:uicontroleventvaluechanged]; [self.view addsubview:segment]; } - ( void )keyboardtypeaction:(id )sender { uisegmentedcontrol *seg = (uisegmentedcontrol *)sender; nslog(@ "intage = %ld" , ( long )seg.selectedsegmentindex); if (seg.selectedsegmentindex == 0) { self.xfg_keyboard = [[xfg_keyboard alloc] initwithnumber:@1]; self.textfield.inputview = self.xfg_keyboard; self.xfg_keyboard.delegate = self; [self.textfield reloadinputviews]; } if (seg.selectedsegmentindex == 1) { self.xfg_keyboard = [[xfg_keyboard alloc] initwithnumber:@2]; self.textfield.inputview = self.xfg_keyboard; self.xfg_keyboard.delegate = self; [self.textfield reloadinputviews]; } if (seg.selectedsegmentindex == 2) { self.xfg_keyboard = [[xfg_keyboard alloc] initwithnumber:@3]; self.textfield.inputview = self.xfg_keyboard; self.xfg_keyboard.delegate = self; [self.textfield reloadinputviews]; } if (seg.selectedsegmentindex == 3) { self.textfield.inputview = nil; [self.textfield reloadinputviews]; } } |
以上就是本文的全部内容,希望对大家学习ios程序设计有所帮助。