ViewController transition by button Touch (no NVController) - ios

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

Related

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];
}

how to perform slide bar navigation so that UITabBar also moves

I have taken a empty application,initially login screen is shown.On entering valid credentials user is navigated to home page where TabBar is shown.On tapping settings icon tab bar should move half way aside.But with my code settings screen is underneath tab bar.How to do so that TabBar also moves.I dont want to use any 3rd part controls.Looking for help.Thanks in advance.Below is my code:
-(void)login{
UIViewController *viewController1 = [[FirstViewController alloc] init];
UINavigationController * firstNavigation = [[UINavigationController alloc]initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] init];
UINavigationController * secondNavigation = [[UINavigationController alloc]initWithRootViewController:viewController2];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = #[firstNavigation ,secondNavigation ];
[self.navigationController pushViewController:tabBarController animated:NO];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_isSideMenuOpen = NO;
UIButton *imageButton1a = [UIButton buttonWithType:UIButtonTypeCustom];
imageButton1a.frame = CGRectMake(0,0,30,30);
[imageButton1a setImage:[UIImage imageNamed:#"setting_icon.png"] forState:UIControlStateNormal];
[imageButton1a addTarget:self action:#selector(goToSettings) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barItem1 = [[UIBarButtonItem alloc] initWithCustomView:imageButton1a];
self.navigationItem.leftBarButtonItem = barItem1;
lbl=[[UILabel alloc]initWithFrame:CGRectMake(10, 100, 150, 30)];
[self.view addSubview:lbl];
lbl.text=#"test label to move";
myView = [[UIView alloc] initWithFrame:self.view.frame];
myView.backgroundColor = [UIColor brownColor];
[myView setFrame:CGRectMake(0, 60, -160, 480)];
[self.view addSubview:myView];
}
-(void)goToSettings
{
if (_isSideMenuOpen)
{
_isSideMenuOpen = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[myView setFrame:CGRectMake(0, 60, -160, 480)];
[UIView commitAnimations];
// self.view.frame=CGRectMake(0,0,320,self.view.frame.size.height);
}
else
{
_isSideMenuOpen = YES;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[myView setFrame:CGRectMake(0, 60, 160, 480)];
[UIView commitAnimations];
// self.view.frame=CGRectMake(160,0,320,self.view.frame.size.height);
}
}
below is screen shot of o/p I got
but expected o/p is UITabBar should move

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"];
}

InputAccessoryView Border?

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.

Resources