Ios 自定义键盘,将文本输入到UITextField

Ios 自定义键盘,将文本输入到UITextField,ios,keyboard,uitextfield,customization,accessoryview,Ios,Keyboard,Uitextfield,Customization,Accessoryview,我很难实现一个键盘附件,当按下附件上的键时,它会将文本输入UITextField。这是一个大致的草图,看起来像: 最终,我希望当用户点击“@gmail”按钮时,它可以输入当前的电子邮件地址UITextField@gmail.com,这样用户就不必输入了。我遇到了一些问题,因为我正在以编程方式编写keyboardaccessoryview,我无法确定是否要将keyboardaccess中的keyinput转到电子邮件地址的UITextField。我试过用这个做一个IBAction NSStrin

我很难实现一个键盘附件,当按下附件上的键时,它会将文本输入UITextField。这是一个大致的草图,看起来像:

最终,我希望当用户点击“@gmail”按钮时,它可以输入当前的电子邮件地址UITextField@gmail.com,这样用户就不必输入了。我遇到了一些问题,因为我正在以编程方式编写keyboardaccessoryview,我无法确定是否要将keyboardaccess中的keyinput转到电子邮件地址的UITextField。我试过用这个做一个IBAction

NSString *appendThisText = @"@gmail.com";
self.textFieldOne.text=[NSString stringWithFormat:@"%@%@", self.textFieldOne.text, appendThisText];
但那没用。我需要帮助。这是我的登录查看控制器.h的代码

#import <UIKit/UIKit.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <AudioToolbox/AudioToolbox.h>

@interface signInViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate> {
    AVAudioPlayer *sound;
    UIButton *myButton;
    UITextField *textFieldOne;
    UIButton *gmailButton;
    UIButton *meButton;
     UIButton *yahooButton;
    UIButton *outlookButton;
    UIView *inputAccView;
    UIButton *aolButton;
}


- (IBAction)playSwoosh:(id)sender;

- (IBAction)dismiss:(id)sender;

- (IBAction)toggleUIButtonImage:(id)sender;

- (IBAction)backgroundTouched:(id)sender;



@property (weak, nonatomic) IBOutlet UITextField *textFieldOne;
@property (weak, nonatomic) IBOutlet UITextField *textFieldTwo;
@property (nonatomic, retain) UIButton *gmailButton;
@property (nonatomic, retain) UIButton *meButton;
@property (nonatomic, retain) UIButton *yahooButton;
@property (nonatomic, retain) UIButton *outlookButton;
@property (nonatomic, retain) UIButton *aolButton;
@property (retain, nonatomic) UIButton *myButton;
@property (nonatomic, retain) UIView *inputAccView;

@end
#导入
#进口
#进口
@界面符号查看控制器:UIViewController{
AVAudioPlayer*声音;
UIButton*myButton;
UITextField*textFieldOne;
UIButton*Gmail按钮;
UIButton*meButton;
UIButton*yahooButton;
UIButton*了望按钮;
UIView*输入视图;
ui按钮*aolButton;
}
-(iAction)Playswosh:(id)发送方;
-(iAction)解雇:(id)发件人;
-(iAction)toggleUIButtonImage:(id)发送方;
-(iAction)背景:(id)发送者;
@属性(弱,非原子)ibuitextfield*textFieldOne;
@属性(弱,非原子)ibuitextfield*textfield2;
@属性(非原子,保留)UIButton*Gmail按钮;
@属性(非原子,保留)UIButton*meButton;
@属性(非原子,保留)UIButton*yahooButton;
@属性(非原子,保留)UIButton*了望按钮;
@属性(非原子,保留)UIButton*aolButton;
@属性(保留,非原子)UIButton*myButton;
@属性(非原子,保留)UIView*InputAcView;
@结束
这是我的信号查看控制器.m

#import "signInViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface signInViewController ()

@end

@implementation signInViewController

@synthesize myButton = _myButton;
@synthesize textFieldOne = _textFieldOne;
@synthesize textFieldTwo = _textFieldTwo;
@synthesize inputAccView;
@synthesize gmailButton;
@synthesize yahooButton;
@synthesize meButton;
@synthesize outlookButton;
@synthesize aolButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}


- (void)createInputAccessoryView {
inputAccView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 310.0, 30.0)];
[inputAccView setBackgroundColor:[UIColor clearColor]];
[inputAccView setAlpha: 0.8];

gmailButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[gmailButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal];
//[gmailButton sizeToFit]
[gmailButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
gmailButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12];
[gmailButton setFrame: CGRectMake(0.0, 0.0, 60.0, 30.0)];
[gmailButton setTitle:@"@Gmail" forState:UIControlStateNormal];
[gmailButton setBackgroundColor:[UIColor lightGrayColor]];
[inputAccView addSubview:gmailButton];

meButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[meButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal];
//[gmailButton sizeToFit]
[meButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
meButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12];
[meButton setFrame: CGRectMake(60.0, 0.0, 50.0, 30.0)];
[meButton setTitle:@"@Me" forState:UIControlStateNormal];
[meButton setBackgroundColor:[UIColor lightGrayColor]];
[inputAccView addSubview:meButton];

yahooButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[yahooButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal];
//[gmailButton sizeToFit]
[yahooButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
yahooButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12];
[yahooButton setFrame: CGRectMake(110.0, 0.0, 70.0, 30.0)];
[yahooButton setTitle:@"@Yahoo" forState:UIControlStateNormal];
[yahooButton setBackgroundColor:[UIColor lightGrayColor]];
[inputAccView addSubview:yahooButton];

outlookButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[outlookButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal];
//[gmailButton sizeToFit]
[outlookButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
outlookButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12];
[outlookButton setFrame: CGRectMake(180.0, 0.0, 70.0, 30.0)];
[outlookButton setTitle:@"@Outlook" forState:UIControlStateNormal];
[outlookButton setBackgroundColor:[UIColor lightGrayColor]];
[inputAccView addSubview:outlookButton];

aolButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[aolButton setBackgroundImage:[UIImage imageNamed:@"keyboardtoolbar.png"] forState:UIControlStateNormal];
//[gmailButton sizeToFit]
[aolButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
aolButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:12];
[aolButton setFrame: CGRectMake(250.0, 0.0, 50.0, 30.0)];
[aolButton setTitle:@"@Aol" forState:UIControlStateNormal];
[aolButton setBackgroundColor:[UIColor lightGrayColor]];
[inputAccView addSubview:aolButton];

}


- (IBAction)backgroundTouched:(id)sender {
[_textFieldOne resignFirstResponder];
[_textFieldTwo resignFirstResponder];
}


- (void)textFieldDidBeginEditing:(UITextField *)textField {

if (textField == self.textFieldOne) {
    [self createInputAccessoryView];
    [textField setInputAccessoryView:inputAccView];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 95), self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
} else if (textField == self.textFieldTwo) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 95), self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == self.textFieldOne) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 95), self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
} else if (textField == self.textFieldTwo) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 95), self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField) {
    [textField resignFirstResponder];
}
return NO;
}
#导入“SignenViewController.h”
#进口
@接口信号查看控制器()
@结束
@实现信号查看控制器
@合成myButton=\u myButton;
@合成textFieldOne=_textFieldOne;
@合成textfieldtow2=_textfieldtow2;
@综合输入视图;
@合成gmailButton;
@合成yahooButton;
@合成按钮;
@综合了望按钮;
@合成aolButton;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
}
回归自我;
}
-(无效)createInputAccessoryView{
InputAcView=[[UIView alloc]initWithFrame:CGRectMake(10.0,0.0,310.0,30.0)];
[InputAcView setBackgroundColor:[UIColor clearColor]];
[InputAcView setAlpha:0.8];
Gmail按钮=[UIButton按钮类型:UIButtonyPeroundRect];
[gmailButton setBackgroundImage:[UIImage ImageName:@“keyboardtoolbar.png”]用于状态:UIControlStateNormal];
//[gmailButton sizeToFit]
[Gmail按钮设置标题颜色:[UIColor blackColor]用于状态:UIControlStateNormal];
gmailButton.titleLabel.font=[UIFont fontWithName:@“Heiti TC”大小:12];
[gmailButton setFrame:CGRectMake(0.0,0.0,60.0,30.0)];
[Gmail按钮设置标题:@“@Gmail”用于状态:UIControlStateNormal];
[gmailButton setBackgroundColor:[UIColor lightGrayColor]];
[输入视图添加子视图:Gmail按钮];
meButton=[UIButton按钮类型:UIButtonTypeRoundRect];
[meButton setBackgroundImage:[UIImage ImageName:@“keyboardtoolbar.png”]用于状态:UIControlStateNormal];
//[gmailButton sizeToFit]
[meButton setTitleColor:[UIColor blackColor]用于状态:UIControlStateNormal];
meButton.titleLabel.font=[UIFont fontWithName:@“Heiti TC”大小:12];
[meButton设置框架:CGRectMake(60.0,0.0,50.0,30.0)];
[meButton设置标题:@“@Me”用于状态:UIControlStateNormal];
[meButton setBackgroundColor:[UIColor lightGrayColor]];
[输入视图添加子视图:meButton];
yahooButton=[UIButton按钮类型:UIButtonyPeroundRect];
[yahooButton setBackgroundImage:[UIImage ImageName:@“keyboardtoolbar.png”]用于状态:UIControlStateNormal];
//[gmailButton sizeToFit]
[yahooButton设置标题颜色:[UIColor blackColor]用于状态:UIControlStateNormal];
yahooButton.titleLabel.font=[UIFont fontWithName:@“Heiti TC”大小:12];
[yahooButton设置框架:CGRectMake(110.0,0.0,70.0,30.0)];
[yahooButton设置标题:@“@Yahoo”for状态:UIControlStateNormal];
[yahooButton setBackgroundColor:[UIColor lightGrayColor]];
[输入视图添加子视图:yahooButton];
outlookButton=[UIButton按钮类型:UIButtonTypeRondRect];
[outlookButton setBackgroundImage:[UIImage ImageName:@“keyboardtoolbar.png”]用于状态:UIControlStateNormal];
//[gmailButton sizeToFit]
[outlookButton setTitleColor:[UIColor blackColor]用于状态:UIControlStateNormal];
outlookButton.titleLabel.font=[UIFont fontWithName:@“Heiti TC”大小:12];
[了望按钮设置框:CGRectMake(180.0,0.0,70.0,30.0)];
[outlookButton集合标题:@“@Outlook”用于状态:UIControlStateNormal];
[outlookButton setBackgroundColor:[UIColor lightGrayColor]];
[输入视图添加子视图:了望按钮];
aolButton=[UIButton Button类型为:UIButtonyPeroundRect]的按钮;
[aolButton setBackgroundImage:[UIImage ImageName:@“keyboardtoolbar.png”]用于状态:UIControlStateNormal];
//[gmailButton sizeToFit]
[aolButton setTitleColor:[UIColor blackColor]用于状态:UIControlStateNormal];
aolButton.titleLabel.font=[UIFont fontWithName:@“Heiti TC”大小:12];
[aolButton设置框架:CGRectMake(250.0,0.0,50.0,30.0)];
[Aol按钮设置标题:@“@Aol”用于状态:UIControlStateNormal];
[aolButton setBackgroundColor:[UIColor lightGrayColor]];
[输入视图添加子视图:aolButton];
}
-(iAction)backgroundTouched:(id)发件人{
[_textFieldOne辞职第一响应者];
[_textFieldTwo辞职第一响应者];
}
-(无效)textFieldDidBeginEditing:(UITextField*)textField{
if(textField==self.textFieldOne){
[self-createInputAccessoryView];
[textField setInputAccessoryView:InputAcView];
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationDelegate:self];
[UIView设置动画持续时间:0.5];
[UIView setAnimationBeginsFromCurrentState:是];
self.view.frame=CGRectMake(self.view.frame.origin.x,(self.view.frame.o
[yourButton addTarget:self action:@selector(yourButtonTapped) forControlEvents:UIControlEventTouchUpInside];
- (void)yourButtonTapped
{
    self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"whatever"];
}