欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS自定义键盘切换效果

程序员文章站 2023-12-11 22:24:40
本文实例为大家分享了ios自定义键盘切换的相关代码,供大家参考,具体内容如下 具体代码如下 - (void)viewdidload { [supe...

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

iOS自定义键盘切换效果

具体代码如下


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

上一篇:

下一篇: