Created
March 25, 2015 20:41
-
-
Save Bardyl/0a4b27c111d88b3acc93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RegisterViewController.m | |
// JuniorExchange | |
// | |
// Created by Florian Pygmalion on 17/03/2015. | |
// Copyright (c) 2015 Florian Pygmalion. All rights reserved. | |
// | |
#import "RegisterViewController.h" | |
#import "User.h" | |
#import "JuniorExchange_Constant.h" | |
#import <AFNetworking/AFNetworking.h> | |
#import <QuartzCore/QuartzCore.h> | |
#import <UIKit/UIKit.h> | |
@interface RegisterViewController () | |
@property (weak, nonatomic) IBOutlet UITextField *firstName; | |
@property (weak, nonatomic) IBOutlet UITextField *lastName; | |
@property (weak, nonatomic) IBOutlet UITextField *mail; | |
@property (weak, nonatomic) IBOutlet UITextField *password; | |
@property (weak, nonatomic) IBOutlet UITextField *juniorCode; | |
@property (strong, nonatomic) IBOutlet UIButton *signinButton; | |
@end | |
@implementation RegisterViewController | |
@synthesize imgPicker = _imgPicker; | |
@synthesize profileImage = _profileImage; | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.navigationItem.title = @"INSCRIPTION"; | |
// Customise Navigation Item bar | |
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 160, 30)]; | |
title.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]; | |
title.text = @"INSCRIPTION"; | |
title.textAlignment = NSTextAlignmentCenter; | |
title.font = [UIFont fontWithName:@"Lato-light" size:20]; | |
[self.navigationItem setTitleView:title]; | |
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:106/255.0 green:62/255.0 blue:130/255.0 alpha:0.2]]; | |
self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; | |
[self.navigationController.navigationBar | |
setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}]; | |
self.navigationController.navigationBar.translucent = YES; | |
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(dismissView:)]; | |
self.navigationItem.rightBarButtonItem = cancelButton; | |
// Change Placeholder Color | |
[[UILabel appearanceWhenContainedIn:[UITextField class], nil] setTextColor:[UIColor colorWithRed:226/255.0f green:207/255.0f blue:229/255.0f alpha:1.0f]]; | |
// Padding Placeholder | |
[self PlaceHolderTextField:self.firstName]; | |
[self PlaceHolderTextField:self.lastName]; | |
[self PlaceHolderTextField:self.mail]; | |
[self PlaceHolderTextField:self.password]; | |
[self PlaceHolderTextField:self.juniorCode]; | |
// Background Opacity Placeholder | |
self.firstName.alpha = 0.8; | |
self.lastName.alpha = 0.8; | |
self.mail.alpha = 0.8; | |
self.password.alpha = 0.8; | |
self.juniorCode.alpha = 0.8; | |
// Border Text Field | |
[self BorderTextField:self.firstName]; | |
[self BorderTextField:self.lastName]; | |
[self BorderTextField:self.mail]; | |
[self BorderTextField:self.password]; | |
[self BorderTextField:self.juniorCode]; | |
// Font Text Field | |
self.firstName.font = [UIFont fontWithName:@"Lato-Italic" size:14]; | |
self.lastName.font = [UIFont fontWithName:@"Lato-Italic" size:14]; | |
self.mail.font = [UIFont fontWithName:@"Lato-Italic" size:14]; | |
self.password.font = [UIFont fontWithName:@"Lato-Italic" size:14]; | |
self.juniorCode.font = [UIFont fontWithName:@"Lato-Italic" size:14]; | |
// Background Image | |
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background"]]; | |
// Shadow Register Button | |
_signinButton.layer.shadowColor = [UIColor blackColor].CGColor; | |
_signinButton.layer.shadowOffset = CGSizeMake(0, 1); | |
_signinButton.layer.shadowOpacity = 0.4; | |
_signinButton.layer.shadowRadius = 2.0; | |
_signinButton.clipsToBounds = NO; | |
// Shadow profile Image | |
_profileImage.layer.shadowColor = [UIColor blackColor].CGColor; | |
_profileImage.layer.shadowOffset = CGSizeMake(0, 1); | |
_profileImage.layer.shadowOpacity = 0.4; | |
_profileImage.layer.shadowRadius = 2.0; | |
_profileImage.clipsToBounds = NO; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
} | |
-(void) viewWillAppear:(BOOL)animated | |
{ | |
// No need to store... this is 1 use only anyway. Save memory, and release it when done. | |
self.imgPicker = [[UIImagePickerController alloc] init]; | |
self.imgPicker.allowsEditing = NO; | |
self.imgPicker.delegate = self; | |
} | |
- (void)PlaceHolderTextField:(UITextField *)name | |
{ | |
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)]; | |
name.leftView = paddingView; | |
name.leftViewMode = UITextFieldViewModeAlways; | |
} | |
- (void)BorderTextField:(UITextField *)name | |
{ | |
name.layer.borderWidth = 0.25; | |
name.layer.borderColor = [[UIColor darkGrayColor] CGColor]; | |
} | |
- (void)dismissView:(id)sender | |
{ | |
[self dismissViewControllerAnimated:YES completion:nil]; | |
} | |
#pragma mark - IBAction Methods | |
- (IBAction)signInButton:(id)sender | |
{ | |
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; | |
NSDictionary *parameters = @{@"firstname": self.firstName.text, | |
@"lastname": self.lastName.text, | |
@"password": self.password.text, | |
@"mail": self.mail.text, | |
@"juniorCode": self.juniorCode.text, | |
}; | |
[manager POST:@"" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { | |
NSLog(@"JSON: %@", responseObject); | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
NSLog(@"Error: %@", error); | |
}]; | |
} | |
-(IBAction)next:(id)sender | |
{ | |
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil | |
delegate:self | |
cancelButtonTitle:@"Cancel" | |
destructiveButtonTitle:nil | |
otherButtonTitles:@"Accéder bibliothèque", @"Prendre photo", nil]; | |
[actionSheet showInView:self.view]; | |
} | |
#pragma mark - UIActionSheetDelegate | |
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex | |
{ | |
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; | |
imagePicker.delegate = self; | |
switch (buttonIndex) { | |
case 0: | |
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; | |
[self presentViewController:imagePicker animated:YES completion:nil]; | |
break; | |
case 1: | |
// Si la caméra n'est pas disponible (surtout pour le simulateur) | |
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | |
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" | |
message:@"Device has no camera" | |
delegate:nil | |
cancelButtonTitle:@"OK" | |
otherButtonTitles: nil]; | |
[myAlertView show]; | |
} | |
else | |
{ | |
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; | |
[self presentViewController:imagePicker animated:YES completion:nil]; | |
} | |
break; | |
} | |
} | |
#pragma mark - ImagePickerControllerDelegate | |
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker | |
{ | |
[picker dismissViewControllerAnimated:YES completion:nil]; | |
} | |
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info | |
{ | |
[picker dismissViewControllerAnimated:YES completion:nil]; | |
UIImage *img = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; | |
self.profileImage.image = [self maskImage:img withMask:[UIImage imageNamed:@"frame.png"]]; | |
NSLog(@"image picked %@",info); | |
} | |
//Masking the image | |
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage | |
{ | |
CGImageRef maskRef = maskImage.CGImage; | |
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), | |
CGImageGetHeight(maskRef), | |
CGImageGetBitsPerComponent(maskRef), | |
CGImageGetBitsPerPixel(maskRef), | |
CGImageGetBytesPerRow(maskRef), | |
CGImageGetDataProvider(maskRef), NULL, false); | |
CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); | |
return [UIImage imageWithCGImage:masked]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment