InputAccessoryView Border? - ios

I'm creating a custom keyboard accessory view. I am currently about 95% done with it. The only thing I have left is to remove the 1px (or 2px?) line above the native iOS keyboard. Is there a way to add a border to the inputaccessoryview so I can use the same color as the keyboard gradient to eliminate the black bar?
Picture Example
If the boarder isn't possible what is the next most logical thing to do with my source code?
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
and 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;
}

Well, after playing around with it, I've decided not to add a boarder because all it did was include an inside boarder. I simply just drew an object to cover it up. But I did find a great resource for those still wondering how to do it! This is another method that would be great for implementation. For you new developers that just want a quick fix, someone did offer for me to simply create another button that was the length of the screen and 3 px high to cover it up, but we all know that s the wrong answer. Just a tip for any newbies
Extend iOS Keyboard Gradient

The KeyboardAccessoryView has a special property hideBorder according to the docs at https://github.com/ardaogulcan/react-native-keyboard-accessory
I suppose InputAccessoryView has the same property.

Related

ViewController transition by button Touch (no NVController)

I have created a button programmatically and added a selector to it
(touched) which when touchup inside should transist to the next view
controller (LocationVC) with no navigationController between. I have
added in storyboard a second view controller and named its class
"LocationVC2. Somehow nothing happens then a black screen. Any help?
//
// ViewController.h
// NanCom4
//
// Created by Daniel Habshush on 8/30/15.
// Copyright © 2015 Daniel Habshush. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIButton *circle1;
#property (nonatomic, strong) IBOutlet UIButton *circle2;
#property (nonatomic, strong) IBOutlet UIButton *circle3;
#property (nonatomic, strong) IBOutlet UIButton *circle4;
#property (nonatomic, strong) IBOutlet UIButton *circle5;
#end
- (void)viewDidLoad {
[super viewDidLoad];
circle1 = [[UIButton alloc] init];
[circle1 setFrame:CGRectMake(128, 247, 100, 100)];
[circle1 setIsAccessibilityElement:YES];
[circle1 addTarget:self action:#selector(pressed3:) forControlEvents:UIControlEventTouchUpInside];
circle1.backgroundColor = [UIColor clearColor];
[circle1 setImage:[UIImage imageNamed:#"Circle6.png"] forState:UIControlStateNormal];
[self.view addSubview:circle1];
circle2 = [[UIButton alloc] init];
[circle2 setFrame:CGRectMake(55, 170, 120, 120)];
[circle2 setIsAccessibilityElement:YES];
[circle2 addTarget:self action:#selector(touch:) forControlEvents:UIControlEventTouchUpInside];
circle2.backgroundColor = [UIColor clearColor];
[circle2 setTitle:#"Orit" forState:UIControlStateNormal];
[circle2 setBackgroundImage: [UIImage imageNamed:#"pie2.png"] forState:UIControlStateNormal];
[self.view addSubview:circle2];
circle3 = [[UIButton alloc] init];
[circle3 setFrame:CGRectMake(55, 300, 120, 120)];
[circle3 setIsAccessibilityElement:YES];
[circle3 setAlpha:0];
circle3.backgroundColor = [UIColor clearColor];
[circle3 setTitle:#"DANI" forState:UIControlStateNormal];
[circle3 setBackgroundImage: [UIImage imageNamed:#"pie3.png"] forState:UIControlStateNormal];
[self.view addSubview:circle3];
circle4 = [[UIButton alloc] init];
[circle4 setFrame:CGRectMake(185, 300, 120, 120)];
[circle4 setIsAccessibilityElement:YES];
[circle4 setAlpha:0];
circle4.backgroundColor = [UIColor clearColor];
[circle4 setTitle:#"DANI" forState:UIControlStateNormal];
[circle4 setBackgroundImage: [UIImage imageNamed:#"pie5.png"] forState:UIControlStateNormal];
[self.view addSubview:circle4];
circle5 = [[UIButton alloc] init];
[circle5 setFrame:CGRectMake(185, 170, 120, 120)];
[circle5 setIsAccessibilityElement:YES];
[circle5 setAlpha:0];
circle5.backgroundColor = [UIColor clearColor];
[circle5 setTitle:#"DANI" forState:UIControlStateNormal];
[circle5 setBackgroundImage: [UIImage imageNamed:#"pie4.png"] forState:UIControlStateNormal];
[self.view addSubview:circle5];
}
- (void)pressed3:(UIButton*)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle1.alpha = 0.2;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle2.alpha = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelay:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle3.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelay:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle4.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelay:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle5.alpha = 1;
[UIView commitAnimations];
}
- (void)touch:(id)sender
{
LocationVC *newVC = [LocationVC new];
[self presentViewController:newVC animated:YES completion:nil];
}
#end

IOS Button touch up inside - First touch = Action1 and second touch = Action2// loop between the two

Hi all
I have attached below code. Upon launch, the view controller displays
a logo in the center and four main user buttons on the bottom.I try to
achieve that if the first button got touched up inside (Called Lists),
the logo fades and the center circle displays the name (Lists) of the
first button and shows around it buttons with different submenu
points, in the same time the 4 main (initial) buttons fade and are
only seen at a minimal (low Alpha). I want to achieve that if the
faded (half visible)main button gets touched again initial view is
restored with logo and only the main four menu buttons. Meaning, first
touch shows sub menus and its animations and second click returns to
initial view. Again clicked shows again submenu and so on. How can i
do that?
Thanks Dnai
//
// ViewController.h
// NanCom1
//
// Created by Daniel Habshush on 8/13/15.
// Copyright © 2015 Daniel Habshush. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, retain) IBOutlet UIImageView* logo;
#property (nonatomic, retain) IBOutlet UIButton* button1;
#property (nonatomic, retain) IBOutlet UIButton* button2;
#property (nonatomic, retain) IBOutlet UIButton* button3;
#property (nonatomic, retain) IBOutlet UIButton* button4;
#property (nonatomic, retain) IBOutlet UIButton* listMain;
#property (nonatomic, retain) IBOutlet UIButton* shoppingList;
#property (nonatomic, retain) IBOutlet UIButton* todoList;
#end
//
// ViewController.m
// NanCom1
//
// Created by Daniel Habshush on 8/13/15.
// Copyright © 2015 Daniel Habshush. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
{
UIDynamicAnimator* _animator;
UIGravityBehavior* _gravity;
UICollisionBehavior* _collision;
}
#synthesize logo, button1, button2, button3, button4, listMain, todoList, shoppingList;
- (void)viewDidLoad {
[super viewDidLoad];
logo = [[UIImageView alloc] init];
UIImage *logoPic = [UIImage imageNamed:#"Logo3.png"];
logo.image=logoPic;
logo.frame = CGRectMake(100, 200, 175, 175);
[logo setAlpha:0];
[self.view addSubview:logo];
[UIImageView beginAnimations:nil context:nil];
[UIImageView setAnimationDuration:3.0];
[UIImageView setAnimationDelay:0.5];
[UIImageView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.logo.alpha = 1.0;
[UIImageView commitAnimations];
button1 = [[UIButton alloc] init];
[button1 setFrame:CGRectMake(5, 2, 90, 90)];
[button1 setIsAccessibilityElement:YES];
button1.backgroundColor = [UIColor clearColor];
[button1 setBackgroundImage:[UIImage imageNamed:#"Circle.png"] forState:UIControlStateNormal];
[button1 setTitle:#"Lists" forState:UIControlStateNormal];
[button1.titleLabel setFont:[UIFont fontWithName:#"Avenir" size:13]];
[button1 addTarget:self action:#selector(pressed:) forControlEvents:UIControlEventTouchUpInside];
[button1 setEnabled:YES];
[self.view addSubview:button1];
button2 = [[UIButton alloc] init];
[button2 setFrame:CGRectMake(85, 2, 90, 90)];
[button2 setIsAccessibilityElement:YES];
button2.backgroundColor = [UIColor clearColor];
[button2 setBackgroundImage:[UIImage imageNamed:#"Circle.png"] forState:UIControlStateNormal];
[button2 setTitle:#"Cirlce" forState:UIControlStateNormal];
[button2.titleLabel setFont:[UIFont fontWithName:#"Avenir" size:13]];
[button2 setEnabled:YES];
[button2 addTarget:self action:#selector(pressed2:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2];
button3 = [[UIButton alloc] init];
[button3 setFrame:CGRectMake(160, 2, 90, 90)];
button3.backgroundColor = [UIColor clearColor];
[button3 setBackgroundImage:[UIImage imageNamed:#"Circle.png"] forState:UIControlStateNormal];
[button3 setTitle:#"Location" forState:UIControlStateNormal];
[button3.titleLabel setFont:[UIFont fontWithName:#"Avenir" size:13]];
[button3 setEnabled:YES];
[button2 addTarget:self action:#selector(pressed3:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button3];
button4 = [[UIButton alloc] init];
[button4 setFrame:CGRectMake(250, 2, 90, 90)];
button4.backgroundColor = [UIColor clearColor];
[button4 setTitle:#"Menu" forState:UIControlStateNormal];
[button4.titleLabel setFont:[UIFont fontWithName:#"Avenir" size:13]];
[button4 setBackgroundImage:[UIImage imageNamed:#"Circle.png"] forState:UIControlStateNormal];
[button4 setEnabled:YES];
[button2 addTarget:self action:#selector(pressed4:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button4];
_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
_gravity = [[UIGravityBehavior alloc] initWithItems:#[button1, button2, button3, button4]];
[_animator addBehavior:_gravity];
_collision = [[UICollisionBehavior alloc]
initWithItems:#[button1, button2, button3, button4]];
_collision.translatesReferenceBoundsIntoBoundary = YES;
[_animator addBehavior:_collision];
UIDynamicItemBehavior* itemBehaviour4 = [[UIDynamicItemBehavior alloc] initWithItems:#[button4]];
itemBehaviour4.elasticity = 0.4;
itemBehaviour4.resistance = 0.65;
[_animator addBehavior:itemBehaviour4];
UIDynamicItemBehavior* itemBehaviour3 = [[UIDynamicItemBehavior alloc] initWithItems:#[button3]];
itemBehaviour3.elasticity = 0.45;
itemBehaviour3.resistance = 0.5;
[_animator addBehavior:itemBehaviour3];
UIDynamicItemBehavior* itemBehaviour2 = [[UIDynamicItemBehavior alloc] initWithItems:#[button2]];
itemBehaviour2.elasticity = 0.5;
itemBehaviour2.resistance = 0.3;
[_animator addBehavior:itemBehaviour2];
UIDynamicItemBehavior* itemBehaviour1 = [[UIDynamicItemBehavior alloc] initWithItems:#[button1]];
itemBehaviour1.elasticity = 0.37;
itemBehaviour1.resistance = 0.2;
[_animator addBehavior:itemBehaviour1];
}
- (void)pressed:(UIButton*)button1 {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.button1.alpha = 0.3;
self.button2.alpha = 0.3;
self.button3.alpha = 0.3;
self.button4.alpha = 0.3;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.logo.alpha = 0;
[UIView commitAnimations];
listMain = [[UIButton alloc] init];
[listMain setFrame:CGRectMake(100, 200, 175, 175)];
listMain.backgroundColor = [UIColor clearColor];
[listMain setBackgroundImage:[UIImage imageNamed:#"Circle.png"] forState:UIControlStateNormal];
[listMain setTitle:#"Lists" forState:UIControlStateNormal];
[listMain.titleLabel setFont:[UIFont fontWithName:#"Avenir" size:35]];
[listMain setAlpha:0];
[self.view addSubview:listMain];
todoList = [[UIButton alloc] init];
[todoList setFrame:CGRectMake(60, 145, 75, 75)];
todoList.backgroundColor = [UIColor clearColor];
[todoList setBackgroundImage:[UIImage imageNamed:#"Circle.png"] forState:UIControlStateNormal];
[todoList setTitle:#"ToDo" forState:UIControlStateNormal];
[todoList.titleLabel setFont:[UIFont fontWithName:#"Avenir" size:13]];
[todoList setAlpha:0];
[self.view addSubview:todoList];
shoppingList = [[UIButton alloc] init];
[shoppingList setFrame:CGRectMake(10, 245, 75, 75)];
shoppingList.backgroundColor = [UIColor clearColor];
[shoppingList setBackgroundImage:[UIImage imageNamed:#"Circle.png"] forState:UIControlStateNormal];
[shoppingList setTitle:#"Shopping" forState:UIControlStateNormal];
[shoppingList.titleLabel setFont:[UIFont fontWithName:#"Avenir" size:13]];
[shoppingList setAlpha:0];
[self.view addSubview:shoppingList];
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.listMain.alpha = 1;
self.todoList.alpha = 1;
self.shoppingList.alpha = 1;
[UIView commitAnimations];
}
- (void)pressed2:(UIButton*)button2 {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.button2.alpha = 1;
self.button1.alpha = 1;
self.button3.alpha = 1;
self.button4.alpha = 1;
self.listMain.alpha = 0;
self.todoList.alpha = 0;
self.shoppingList.alpha = 0;
[UIView commitAnimations];
}
- (void)pressed3:(UIButton*)button3 {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.listMain.alpha = 0;
self.todoList.alpha = 0;
self.shoppingList.alpha = 0;
self.logo.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.button2.alpha = 1;
self.button1.alpha = 1;
self.button3.alpha = 1;
self.button4.alpha = 1;
[UIView commitAnimations];
}
- (void)pressed4:(UIButton*)button4 {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.button2.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.button1.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.button3.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.button4.alpha = 1;
[UIView commitAnimations];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

Show a UIViewController as Alert View in iOS

I'm trying to create a custom Alert View similar to this
I want to use a View Controller as the alert because the 'X' button on the top left corner must be there, and neither a regular UIAlertController or any pod I found can help me with that.
How can I achieve this?
Thank you.
For showing viewController as UIAlertView try this
SecondViewController *secondViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"SecondViewController"];
secondViewController.view.frame = self.view.frame;
[self.view addSubview:secondViewController.view];
secondViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
secondViewController.view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
}];
try this..
#interface alertViewController ()
{
UILabel *labelTitle;
UIView *viewToShow,*viewAlert;
}
#end
#implementation alertViewController
- (void)viewDidLoad
{
[super viewDidLoad];
viewToShow = [[UIView alloc]initWithFrame:CGRectMake(0,0, 165*2, 400)];
[viewToShow setBackgroundColor:[UIColor whiteColor]];
[viewToShow setOpaque:NO];
[self.navigationController.view addSubview:viewToShow];
labelTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 165*2, 30)];
[[labelTitle layer] setCornerRadius:14];
labelTitle.text=#"TITLE";
[labelTitle setTextAlignment:NSTextAlignmentCenter];
[viewToShow addSubview:labelTitle];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(cancelButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"X" forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont fontWithName:#"helvetica-neue" size:20]];
button.frame = CGRectMake(5,5,30, 40.0);
[viewToShow addSubview:button];
UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(10, 60,viewToShow.frame.size.width-20, 250)];
[textView setBackgroundColor:[UIColor lightGrayColor]];
[viewToShow addSubview:textView];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self
action:#selector(cancelButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:#"Continue" forState:UIControlStateNormal];
button1.frame = CGRectMake((viewToShow.frame.size.width/2)-40,viewToShow.frame.size.height-40,80,40);
[viewToShow addSubview:button1];
[[viewToShow layer] setCornerRadius:14];
CGPoint centerForCustomExportView;
if (UIDeviceOrientationIsLandscape((UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]))
{
centerForCustomExportView = CGPointMake(([[UIScreen mainScreen]bounds].size.height>[[UIScreen mainScreen]bounds].size.width?[[UIScreen mainScreen]bounds].size.height:[[UIScreen mainScreen]bounds].size.width)/2, (([[UIScreen mainScreen]bounds].size.height>[[UIScreen mainScreen]bounds].size.width?[[UIScreen mainScreen]bounds].size.width:[[UIScreen mainScreen]bounds].size.height)/2));
}
else
{
centerForCustomExportView = CGPointMake([[UIScreen mainScreen]bounds].size.width/2, ([[UIScreen mainScreen]bounds].size.height-self.navigationController.navigationBar.frame.size.height)/2);
}
viewToShow.center = centerForCustomExportView;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceRotated:)name:UIDeviceOrientationDidChangeNotification object:nil];
}
try this.....
- (void)show
{
NSLog(#"show");
isShown = YES;
self.transform = CGAffineTransformMakeScale(0.1, 0.1);
self.alpha = 0;
[UIView beginAnimations:#"showAlert" context:nil];
[UIView setAnimationDelegate:self];
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
self.alpha = 1;
[UIView commitAnimations];
}

Custom Alertview with delegates without storyboard

I have design custom alerview for my project.
I create a seperate viewcontroller(.h and .m) files with #protocol for the delegates to get alertview button click response. I have create an object for the view controller(custom alertview which i create with custom delegate). and I subview the custom alertview in each of other classes. Its working as normal UIAlertview.
But the issue occurs on when I show the alertview and then press the home button and return to my app its getting freeze in ios7 and in ios6 getting crash.
What should I do to fix this issue. It(alert view) should work as normal when i return to my app. Please give your ideas to fix this.
I cant find how the apple default UIAlertview work when in the same(dipaly alertview and enter into background and rentun into app the displayed alertview works fine).
I m not use UIAlertvie
alert_cupboard=[[UIAlertView alloc]initWithTitle:#"Title" message:#"message" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Yes",#"No", nil];
alert_cupboard.tag=0;
[alert_cupboard show];
For that, I have design in My code for create Custom Alertview
CustomAlertView.h
#protocol AlertViewprotocal <NSObject>
#required
- (void)AlertSuccess:(id)result;
- (void)AlertFailure:(id)result;
#end
#interface CustomAlertView : UIViewController
{
UIView *view_alert;
UIImageView *img_alert_bg;
UIView *view_alert_popup;
UILabel *lbl_alert_title;
UILabel *lbl_alert_message;
UILabel *lbl_sep_horizontal;
UILabel *lbl_sep_vertical;
UIButton *btn_alert_OK;
UIButton *btn_alert_yes;
UIButton *btn_alert_no;
}
#property(nonatomic,weak)id<AlertViewprotocal> CustomAlertdelegate;
+(CustomAlertView *)singleton;
-(void)showAlertView:(UIViewController *)rootViewController:(NSInteger)option :(NSString *)message :(NSInteger)tag;
-(IBAction)action_alert_yes:(id)sender;
-(IBAction)action_alert_hide:(id)sender;
#end
CustomAlertView.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
float height=[UIScreen mainScreen].bounds.size.height;
float width=[UIScreen mainScreen].bounds.size.width;
view_alert=[[UIView alloc]initWithFrame:CGRectMake(0, 0,width , height)];
img_alert_bg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,width , height)];
[img_alert_bg setImage:[UIImage imageNamed:#"pop_up_bg.png"]];
[view_alert addSubview:img_alert_bg];
view_alert_popup=[[UIView alloc]initWithFrame:CGRectMake(IS_IPAD ? (234): 10, (height-156)/2, IS_IPAD ? (300):(width-(10*2)) , 156)];
[view_alert_popup setBackgroundColor:[UIColor whiteColor]];
view_alert_popup.layer.cornerRadius= 10.5; //IS_IPAD ?8.2:
lbl_alert_title=[[UILabel alloc]initWithFrame:CGRectMake(20, 5, 260, 35.0)];
[lbl_alert_title setTextColor:[UIColor blackColor]];
[lbl_alert_title setBackgroundColor:[UIColor clearColor]];
[lbl_alert_title setText:#"Title"];
lbl_alert_title.textAlignment = UITextAlignmentCenter;
lbl_alert_title.font = [UIFont fontWithName:#"Helvetica" size: 18.0]; //IS_IPAD ? 34.0 :
[view_alert_popup addSubview:lbl_alert_title];
lbl_alert_message=[[UILabel alloc]initWithFrame:CGRectMake(20, lbl_alert_title.frame.size.height, view_alert_popup.frame.size.width-(20*2), 70)];
[lbl_alert_message setTextColor:[UIColor blackColor]];
[lbl_alert_message setBackgroundColor:[UIColor clearColor]];
lbl_alert_message.font = [UIFont fontWithName:#"Helvetica" size: 16.0]; //IS_IPAD ? 34.0 :
lbl_alert_message.textAlignment = UITextAlignmentCenter;
lbl_alert_message.numberOfLines=3;
lbl_alert_message.lineBreakMode=UILineBreakModeWordWrap;
[view_alert_popup addSubview:lbl_alert_message];
lbl_sep_horizontal=[[UILabel alloc]initWithFrame:CGRectMake(0, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height), view_alert_popup.frame.size.width, 1.0)];
[lbl_sep_horizontal setBackgroundColor:[UIColor lightGrayColor]];
[view_alert_popup addSubview:lbl_sep_horizontal];
lbl_sep_vertical=[[UILabel alloc]initWithFrame:CGRectMake(150, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height), 1.0, 50.0)];
[lbl_sep_vertical setBackgroundColor:[UIColor lightGrayColor]];
[view_alert_popup addSubview:lbl_sep_vertical];
btn_alert_yes=[[UIButton alloc]initWithFrame:CGRectMake(0, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height+10), 150, 30.0)];
[btn_alert_yes setBackgroundColor:[UIColor clearColor]];
[btn_alert_yes setTitleColor:[UIColor colorWithRed:(204.0/255.0) green:(50.0/255.0) blue:(100.0/255.0) alpha:1.0] forState:UIControlStateNormal];
[btn_alert_yes.titleLabel setFont:[UIFont fontWithName:#"Helvetica" size: 16.0]];
[btn_alert_yes setTitle:#"Yes" forState:UIControlStateNormal];
//[btn_alert_yes.titleLabel setText:#"Yes"];
[btn_alert_yes addTarget:self action:#selector(action_alert_yes:) forControlEvents:UIControlEventTouchUpInside];
[view_alert_popup addSubview:btn_alert_yes];
btn_alert_no=[[UIButton alloc]initWithFrame:CGRectMake(150, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height+10), 150, 30.0)];
[btn_alert_no setBackgroundColor:[UIColor clearColor]];
[btn_alert_no setTitleColor:[UIColor colorWithRed:(204.0/255.0) green:(50.0/255.0) blue:(100.0/255.0) alpha:1.0] forState:UIControlStateNormal];
[btn_alert_no.titleLabel setFont:[UIFont fontWithName:#"Helvetica" size: 16.0]];
[btn_alert_no setTitle:#"No" forState:UIControlStateNormal];
//[btn_alert_no.titleLabel setText:#"No"];
[btn_alert_no addTarget:self action:#selector(action_alert_hide:) forControlEvents:UIControlEventTouchUpInside];
[view_alert_popup addSubview:btn_alert_no];
btn_alert_OK=[[UIButton alloc]initWithFrame:CGRectMake(0, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height+10), 300, 30.0)];
[btn_alert_OK setBackgroundColor:[UIColor clearColor]];
[btn_alert_OK setTitleColor:[UIColor colorWithRed:(204.0/255.0) green:(50.0/255.0) blue:(100.0/255.0) alpha:1.0] forState:UIControlStateNormal];
[btn_alert_OK.titleLabel setFont:[UIFont fontWithName:#"Helvetica" size: 16.0]];
[btn_alert_OK setTitle:#"OK" forState:UIControlStateNormal];
//[btn_alert_OK.titleLabel setText:#"OK"];
[btn_alert_OK addTarget:self action:#selector(action_alert_hide:) forControlEvents:UIControlEventTouchUpInside];
[view_alert_popup addSubview:btn_alert_OK];
[view_alert addSubview:view_alert_popup];
[self.view addSubview:view_alert];
}
return self;
}
+(CustomAlertView *)singleton
{
if (shared)
{
shared=nil;
}
shared = [[CustomAlertView alloc] init];
return shared;
}
-(void)showAlertView:(UIViewController *)rootViewController:(NSInteger)option :(NSString *)message :(NSInteger)tag
{
lbl_alert_message.text=message;
view_alert.tag=tag;
if (option==1)
{
[btn_alert_OK setHidden:NO];
btn_alert_OK.tag=tag;
[btn_alert_yes setHidden:YES];
[btn_alert_no setHidden:YES];
[lbl_sep_horizontal setHidden:NO];
[lbl_sep_vertical setHidden:YES];
}
else
{
[btn_alert_OK setHidden:YES];
[btn_alert_yes setHidden:NO];
[btn_alert_no setHidden:NO];
[lbl_sep_horizontal setHidden:NO];
[lbl_sep_vertical setHidden:NO];
btn_alert_yes.tag=tag;
}
view_alert_popup.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[UIView animateWithDuration:0.4/1.5 animations:^
{
view_alert_popup.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished)
{
[UIView animateWithDuration:0.4/2 animations:^
{
[rootViewController.view addSubview:self.view];
view_alert_popup.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
} completion:^(BOOL finished)
{
[UIView animateWithDuration:0.4/2 animations:^{
view_alert_popup.transform = CGAffineTransformIdentity;
}];
}];
}];
}
-(IBAction)action_alert_yes:(id)sender
{
[self.view removeFromSuperview];
[self.CustomAlertdelegate AlertSuccess:view_alert];
}
-(IBAction)action_alert_hide:(id)sender
{
[self.view removeFromSuperview];
[self.CustomAlertdelegate AlertFailure:view_alert];
}
I have use the custome alertview in other my view controller
HomeView.h
#interface HomeScreen :UIViewController <AlertViewprotocal> //CustomAlertView
{
CustomAlertView *alert;
}
HomeView.m
-(void)viewWillAppear:(BOOL)animated
{
alert=[CustomAlertView singleton];
alert.CustomAlertdelegate=self;
}
- (void)viewWillDisappear:(BOOL)animated
{
alert.CustomAlertdelegate=nil;
}
-(IBAction)action_addRemove:(id)sender
{
UIButton *btn=sender;
self.add_row=btn.tag;
[alert showAlertView:self :2 :#"message" :0];
}
- (void)AlertSuccess:(id)result
{
UIView *vw=result;
NSLog(#"Success tag:%d",vw.tag);
switch (vw.tag)
{
case 0:
{
[self remove];
}
break;
case 1:
{
[self add];
}
break;
default:
break;
}
}
- (void)AlertFailure:(id)result
{
UIView *vw=result;
NSLog(#"Failure tag:%d",vw.tag);
}
I got
-[__NSArrayM action_alert_yes:]: unrecognized selector sent to instance 0xc135350
Stack trace: NSInvalidArgumentException
I think you have not put "nil" parameter at the end of your custom alert view.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"error" message:#"message" delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"otherbutton", nil];
nil is last parameter.

Custom Keyboard with Text Input to UITextField

I'm having difficulties with implementing a keyboard accessory that inputs text into a UITextField when a key is pressed on the accessory. This is was the rough draft looks like:
Keyboard Accessory Picture
Ultimately I want when the user clicks on the '#gmail button for it to enter in the current email address UITextField #gmail.com so the user doesn't have to type it out. I have run into problems because I am writing the keyboardaccessoryview programmatically, I can't figure out have the keyinput from the keyboardaccess go to the UITextField of the email address. I have tried doing an IBAction with the
NSString *appendThisText = #"#gmail.com";
self.textFieldOne.text=[NSString stringWithFormat:#"%#%#", self.textFieldOne.text, appendThisText];
but that didn't work. I need help please. Here is my code for the 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;
}
- (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
and here is my 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;
- (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;
}
Can someone please help me get on the right path with this one. I assume it would be an IBAction from gmailButton to textFieldOne as the outlet but I'm not sure how to implement that programmatically. It's giving me some issues. I have no problems translating this to a UITextView but i don't know if I need to use the UITextInput protocol or what.
Basically you'll just have to add some target-action to you buttons (like an IBAction).
Just add this to your Buttons:
[yourButton addTarget:self action:#selector(yourButtonTapped) forControlEvents:UIControlEventTouchUpInside];
And create a method to handle the tap, like:
- (void)yourButtonTapped
{
self.textFieldOne.text = [self.textFieldOne.text stringByAppendingString:#"whatever"];
}

Resources