服务器之家

服务器之家 > 正文

iOS自定义键盘切换效果

时间:2021-01-17 20:38     来源/作者:缘丶天灬

本文实例为大家分享了ios自定义键盘切换的相关代码,供大家参考,具体内容如下

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程序设计有所帮助。

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
返回顶部