InputAccessoryView边框?

时间:2013-05-11 18:56:17

标签: ios keyboard border accessory

我正在创建自定义键盘配件视图。我目前约95%完成了它。我唯一剩下的就是删除原生iOS键盘上方的1px(或2px?)行。有没有办法在inputaccessoryview中添加边框,这样我就可以使用与键盘渐变相同的颜色来消除黑条?

Picture Example

如果无法使用边界,那么对我的源代码来说,下一个最合理的事情是什么?

signInViewController.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;
UIButton *milButton;
}


- (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 (nonatomic, retain) UIButton *milButton;
@property (retain, nonatomic) UIButton *myButton;
@property (nonatomic, retain) UIView *inputAccView;

@end

signInViewController.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;
@synthesize milButton;

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

- (void)gmailButtonTapped
{
self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"@gmail.com"];
}

- (void)meButtonTapped
{
self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"@me.com"];
}

- (void)outlookButtonTapped
{
self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"@outlook.com"];
}

- (void)yahooButtonTapped
{
self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"@yahoo.com"];
}

- (void)aolButtonTapped
{
self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"@aol.com"];
}

- (void)milButtonTapped
{
self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:@"@mail.mil"];
}


- (void)createInputAccessoryView {
inputAccView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 310.0, 40.0)];
[inputAccView setBackgroundColor:[UIColor colorWithRed:0.569 green:0.600 blue:0.643 alpha:1.000]];
[inputAccView setAlpha: 0.8];     

// GMAIL BUTTON ADDED

gmailButton = [UIButton buttonWithType: UIButtonTypeCustom];
[gmailButton setFrame:CGRectMake(9.5, 4.5, 60.0, 30.0)];
[gmailButton setBackgroundColor:[UIColor colorWithRed:(241/255.0) green:(242/255.0) blue:(242/255.0) alpha:1]];
[inputAccView addSubview:gmailButton];

gmailButton.layer.cornerRadius = 5;
gmailButton.layer.masksToBounds = NO;
gmailButton.layer.shadowColor = [UIColor blackColor].CGColor;
gmailButton.layer.shadowOpacity = 0.8;
gmailButton.layer.shadowRadius = 2;
gmailButton.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);

[gmailButton setTitle:@"@Gmail" forState:UIControlStateNormal];
[gmailButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[gmailButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
gmailButton.titleLabel.font = [UIFont fontWithName:@"Helvetica Neue Bold" size:12];

[gmailButton addTarget:self action:@selector(gmailButtonTapped) forControlEvents:UIControlEventTouchUpInside];

// ME BUTTON ADDED

meButton = [UIButton buttonWithType: UIButtonTypeCustom];
[meButton setFrame:CGRectMake(73.5, 4.5, 40.0, 30.0)];
[meButton setBackgroundColor:[UIColor colorWithRed:(241/255.0) green:(242/255.0) blue:(242/255.0) alpha:1]];
[inputAccView addSubview:meButton];

meButton.layer.cornerRadius = 5;
meButton.layer.masksToBounds = NO;
meButton.layer.shadowColor = [UIColor blackColor].CGColor;
meButton.layer.shadowOpacity = 0.8;
meButton.layer.shadowRadius = 2;
meButton.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);

[meButton setTitle:@"@Me" forState:UIControlStateNormal];
[meButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[meButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
meButton.titleLabel.font = [UIFont fontWithName:@"Helvetica Neue Bold" size:12];

[meButton addTarget:self action:@selector(meButtonTapped) forControlEvents:UIControlEventTouchUpInside];

// YAHOO BUTTON ADDED

yahooButton = [UIButton buttonWithType: UIButtonTypeCustom];
[yahooButton setFrame:CGRectMake(117.5, 4.5, 65.0, 30.0)];
[yahooButton setBackgroundColor:[UIColor colorWithRed:(241/255.0) green:(242/255.0) blue:(242/255.0) alpha:1]];
[inputAccView addSubview:yahooButton];

yahooButton.layer.cornerRadius = 5;
yahooButton.layer.masksToBounds = NO;
yahooButton.layer.shadowColor = [UIColor blackColor].CGColor;
yahooButton.layer.shadowOpacity = 0.8;
yahooButton.layer.shadowRadius = 2;
yahooButton.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);

[yahooButton setTitle:@"@Yahoo" forState:UIControlStateNormal];
[yahooButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[yahooButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
yahooButton.titleLabel.font = [UIFont fontWithName:@"Helvetica Neue Bold" size:12];

[yahooButton addTarget:self action:@selector(yahooButtonTapped) forControlEvents:UIControlEventTouchUpInside];

// OUTLOOK BUTTON ADDED

outlookButton = [UIButton buttonWithType: UIButtonTypeCustom];
[outlookButton setFrame:CGRectMake(186.5, 4.5, 77.0, 30.0)];
[outlookButton setBackgroundColor:[UIColor colorWithRed:(241/255.0) green:(242/255.0) blue:(242/255.0) alpha:1]];
[inputAccView addSubview:outlookButton];

outlookButton.layer.cornerRadius = 5;
outlookButton.layer.masksToBounds = NO;
outlookButton.layer.shadowColor = [UIColor blackColor].CGColor;
outlookButton.layer.shadowOpacity = 0.8;
outlookButton.layer.shadowRadius = 2;
outlookButton.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);

[outlookButton setTitle:@"@Outlook" forState:UIControlStateNormal];
[outlookButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[outlookButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
outlookButton.titleLabel.font = [UIFont fontWithName:@"Helvetica Neue Bold" size:12];

[outlookButton addTarget:self action:@selector(outlookButtonTapped) forControlEvents:UIControlEventTouchUpInside];

// AOL BUTTON ADDED

aolButton = [UIButton buttonWithType: UIButtonTypeCustom];
[aolButton setFrame:CGRectMake(267.5, 4.5, 41.0, 30.0)];
[aolButton setBackgroundColor:[UIColor colorWithRed:(241/255.0) green:(242/255.0) blue:(242/255.0) alpha:1]];
[inputAccView addSubview:aolButton];

aolButton.layer.cornerRadius = 5;
aolButton.layer.masksToBounds = NO;
aolButton.layer.shadowColor = [UIColor blackColor].CGColor;
aolButton.layer.shadowOpacity = 0.8;
aolButton.layer.shadowRadius = 2;
aolButton.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);

[aolButton setTitle:@"@Aol" forState:UIControlStateNormal];
[aolButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[aolButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
aolButton.titleLabel.font = [UIFont fontWithName:@"Helvetica Neue Bold" size:12];

[aolButton addTarget:self action:@selector(aolButtonTapped) forControlEvents:UIControlEventTouchUpInside];

}

- (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 {
NSInteger nextTag = textField.tag + 1;
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
    [nextResponder becomeFirstResponder];
} else {
    [textField resignFirstResponder];
}
return  NO;
}

2 个答案:

答案 0 :(得分:0)

好吧,在玩完它之后,我决定不添加寄宿生,因为它所做的一切都包括一个内部寄宿生。我只是画了一个物体来掩盖它。但我确实为那些仍然想知道怎么做的人找到了一个很好的资源!这是另一种非常适合实现的方法。对于那些只想要快速修复的新开发人员,有人确实为我提供了简单地创建另一个按钮,该按钮是屏幕的长度和3 px高,以掩盖它,但我们都知道这是错误的答案。只是任何新手的小费

Extend iOS Keyboard Gradient

答案 1 :(得分:0)

根据https://github.com/ardaogulcan/react-native-keyboard-accessory上的文档,KeyboardAccessoryView具有特殊属性hideBorder 我想InputAccessoryView具有相同的属性。