//
//  Accepting_User_Text_Input_with_UITextFieldViewController.m
//  Accepting User Text Input with UITextField
//
//  Created by Vandad Nahavandipoor on 10/07/2011.
//  Copyright 2011 Pixolity Ltd. All rights reserved.
//

/* 1 */
//#import "Accepting_User_Text_Input_with_UITextFieldViewController.h"
//
//@implementation Accepting_User_Text_Input_with_UITextFieldViewController
//
//@synthesize myTextField;

/* 2 */
#import "Accepting_User_Text_Input_with_UITextFieldViewController.h"

@implementation Accepting_User_Text_Input_with_UITextFieldViewController

@synthesize myTextField;
@synthesize labelCounter;

- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
  // Usunięcie wszelkich buforowanych danych, obrazów itd., które nie są obecnie używane.
}

#pragma mark - Cykl życiowy widoku

/* 1 */
//- (void)viewDidLoad{
//  [super viewDidLoad];
//  
//  self.view.backgroundColor = [UIColor whiteColor];
//  CGRect textFieldFrame = CGRectMake(0.0f,
//                                     0.0f,
//                                     200.0f, 
//                                     31.0f);
//	
//  self.myTextField = [[UITextField alloc]
//                      initWithFrame:textFieldFrame];
//  self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
//  
//  self.myTextField.contentVerticalAlignment = 
//    UIControlContentVerticalAlignmentCenter;
//  
//  self.myTextField.textAlignment = UITextAlignmentCenter;
//  
//  self.myTextField.text = @"Pan Jan Kowalski";
//  self.myTextField.center = self.view.center;
//  [self.view addSubview:self.myTextField];
//  
//}

/* 2 */
//- (void)viewDidLoad{
//  [super viewDidLoad];
//  
//  self.view.backgroundColor = [UIColor whiteColor];
//  CGRect textFieldFrame = CGRectMake(0.0f,
//                                     0.0f,
//                                     200.0f, 
//                                     31.0f);
//	
//  self.myTextField = [[UITextField alloc]
//                      initWithFrame:textFieldFrame];
//  
//  self.myTextField.delegate = self;
//  
//  self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
//  
//  self.myTextField.contentVerticalAlignment = 
//    UIControlContentVerticalAlignmentCenter;
//  
//  self.myTextField.textAlignment = UITextAlignmentCenter;
//  
//  self.myTextField.text = @"Pan Jan Kowalski";
//  self.myTextField.center = self.view.center;
//  [self.view addSubview:self.myTextField];
//  
//}

/* 3 */
//- (void) calculateAndDisplayTextFieldLengthWithText:(NSString *)paramText{
//  
//  NSString *characterOrCharacters = @"znaki";
//  if ([paramText length] == 1){
//    characterOrCharacters = @"znak";
//  }
//  
//  self.labelCounter.text = [NSString stringWithFormat:@"%lu %@",
//                            (unsigned long)[paramText length],
//                            characterOrCharacters];
//}
//
//- (BOOL)                textField:(UITextField *)textField 
//    shouldChangeCharactersInRange:(NSRange)range 
//                replacementString:(NSString *)string{
//  
//  BOOL result = YES;
//  
//  if ([textField isEqual:self.myTextField]){
//    NSString *wholeText = 
//    [textField.text stringByReplacingCharactersInRange:range
//                                            withString:string];
//    [self calculateAndDisplayTextFieldLengthWithText:wholeText];
//  }
//  
//  return result;
//  
//}
//
//- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//  [textField resignFirstResponder];
//  return YES;
//}
//
//- (void)viewDidLoad{
//  [super viewDidLoad];
//  
//  self.view.backgroundColor = [UIColor whiteColor];
//  CGRect textFieldFrame = CGRectMake(38.0f,
//                                     30.0f,
//                                     220.0f, 
//                                     31.0f);
//	
//  self.myTextField = [[UITextField alloc]
//                      initWithFrame:textFieldFrame];
//  
//  self.myTextField.delegate = self;
//  
//  self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
//  
//  self.myTextField.contentVerticalAlignment = 
//    UIControlContentVerticalAlignmentCenter;
//  
//  self.myTextField.textAlignment = UITextAlignmentCenter;
//  
//  self.myTextField.text = @"Pan Jan Kowalski";
//  [self.view addSubview:self.myTextField];
//  
//  CGRect labelCounterFrame = self.myTextField.frame;
//  labelCounterFrame.origin.y += textFieldFrame.size.height + 10;
//  self.labelCounter = [[UILabel alloc] initWithFrame:labelCounterFrame];
//  [self.view addSubview:self.labelCounter];
//  
//  [self calculateAndDisplayTextFieldLengthWithText:self.myTextField.text];
//  
//}

/* 4 */
//- (void) calculateAndDisplayTextFieldLengthWithText:(NSString *)paramText{
//  
//  NSString *characterOrCharacters = @"znaków";
//  if ([paramText length] == 1){
//    characterOrCharacters = @"znak";
//  }
//  
//  self.labelCounter.text = [NSString stringWithFormat:@"%lu %@",
//                            (unsigned long)[paramText length],
//                            characterOrCharacters];
//}
//
//- (BOOL)                textField:(UITextField *)textField 
//    shouldChangeCharactersInRange:(NSRange)range 
//                replacementString:(NSString *)string{
//  
//  BOOL result = YES;
//  
//  if ([textField isEqual:self.myTextField]){
//    NSString *wholeText = 
//    [textField.text stringByReplacingCharactersInRange:range
//                                            withString:string];
//    [self calculateAndDisplayTextFieldLengthWithText:wholeText];
//  }
//  
//  return result;
//  
//}
//
//- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//  [textField resignFirstResponder];
//  return YES;
//}
//
//- (void)viewDidLoad{
//  [super viewDidLoad];
//  
//  self.view.backgroundColor = [UIColor whiteColor];
//  CGRect textFieldFrame = CGRectMake(38.0f,
//                                     30.0f,
//                                     220.0f, 
//                                     31.0f);
//	
//  self.myTextField = [[UITextField alloc]
//                      initWithFrame:textFieldFrame];
//  
//  self.myTextField.delegate = self;
//  
//  self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
//  
//  self.myTextField.contentVerticalAlignment = 
//    UIControlContentVerticalAlignmentCenter;
//  
//  self.myTextField.textAlignment = UITextAlignmentCenter;
//  
//  self.myTextField.placeholder = @"Podaj dowolny tekst...";
//  [self.view addSubview:self.myTextField];
//  
//  CGRect labelCounterFrame = self.myTextField.frame;
//  labelCounterFrame.origin.y += textFieldFrame.size.height + 10;
//  self.labelCounter = [[UILabel alloc] initWithFrame:labelCounterFrame];
//  [self.view addSubview:self.labelCounter];
//  
//  [self calculateAndDisplayTextFieldLengthWithText:self.myTextField.text];
//  
//}

/* 5 */
- (void)viewDidLoad{
  [super viewDidLoad];
  
  self.view.backgroundColor = [UIColor whiteColor];
  
  CGRect textFieldFrame = CGRectMake(38.0f,
                                     30.0f,
                                     240.0f, 
                                     31.0f);
	
  self.myTextField = [[UITextField alloc]
                      initWithFrame:textFieldFrame];
  
  self.myTextField.keyboardType = UIKeyboardTypeDecimalPad;
  
  self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
  
  self.myTextField.contentVerticalAlignment = 
    UIControlContentVerticalAlignmentCenter;
  
  self.myTextField.textAlignment = UITextAlignmentLeft;
  
  self.myTextField.placeholder = @"Podaj dowolną kwotę.";
  [self.view addSubview:self.myTextField];
  
  UILabel *currencyLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  currencyLabel.text = [[[NSNumberFormatter alloc] init] currencySymbol];
  currencyLabel.font = self.myTextField.font;
  [currencyLabel sizeToFit];
  self.myTextField.rightView = currencyLabel;
  self.myTextField.rightViewMode = UITextFieldViewModeAlways;
  
}

- (void)viewDidUnload
{
  [super viewDidUnload];
  // Usunięcie wszystkich "przytrzymanych" podwidoków widoku głównego,
  // na przykład self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  // Zwrot wartości YES dla obsługiwanych układów.
  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  } else {
    return YES;
  }
}

@end
