//
//  abcViewController.m
//  UITest4
//
//  Created by UEC on 19/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onButtonClicked:(id)sender {
    
    self.myLabel.text = [NSString stringWithFormat:@"I am a String"];
    
}
- (IBAction)onChanged:(id)sender {
    int value = self.mySegmentedControl.selectedSegmentIndex;
    
    if(value==0){
      self.myLabel.text = [NSString stringWithFormat:@"You selectd first"];
    }else{
      self.myLabel.text = [NSString stringWithFormat:@"You selectd second"];
    }

    // self.myLabel.text = [NSString stringWithFormat:@"You selectd %i",value];
}
- (IBAction)onSliderChanged:(id)sender {
    
    float value = self.mySlider.value * 10;
    
    self.myLabel.text = [NSString stringWithFormat:@"You value is %1.0f",value];
    
}
- (IBAction)onSwitchChanged:(id)sender {
    BOOL value = self.mySwitch.on;
    if(value==0){
      self.myLabel.text = [NSString stringWithFormat:@"You switch is off."];
    } else{
       self.myLabel.text = [NSString stringWithFormat:@"You value is on."];
    }
    
}
@end

//
//  abcViewController.m
//  UITest5
//
//  Created by UEC on 19/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onClick:(id)sender {

    NSString *name = self.nameText.text;
    NSString *password = self.passwordText.text;
    
    // name is Peter, password 12345, sucess
    if([name isEqualToString:@"Peter"]&&[password isEqualToString:@"12345"] ){
        self.resultText.text = [NSString stringWithFormat:@"Login Success"];
    } else {
        self.resultText.text = [NSString stringWithFormat:@"Login Fail"];
    }
    if([self.nameText isFirstResponder]){
        [sender resignFirstResponder];
    }
    if([self.passwordText isFirstResponder]){
        [sender resignFirstResponder];
    }

}
- (IBAction)onNameExit:(id)sender {
        [sender resignFirstResponder];
}

- (IBAction)onPasswordExit:(id)sender {
        [sender resignFirstResponder];
}
@end

//
//  abcViewController.m
//  UITest6
//
//  Created by UEC on 19/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)changeDatePicker:(id)sender {
    
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy/MM/dd:HH:mm";
    self.myLabel.text = [df stringFromDate:self.UIDatePicker.date];

}
@end

// Alert Ok Cancel
//
//  abcViewController.m
//  UITest7
//
//  Created by UEC on 19/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onClick:(id)sender {
    
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Agree with me ?" message:@"Do you agree with me?" delegate:self cancelButtonTitle:@"Disagree" otherButtonTitles:@"Agree",nil];
    [alert show];

    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if(buttonIndex == 1) {
        self.myLabel.text = [NSString stringWithFormat:@"Agree"];
    
    } else {
            self.myLabel.text = [NSString stringWithFormat:@"Disagree"];
    
    }

}
@end

___________________________
class 3

____________________________

Map View, Image View, Label, Label
__________________________

//
//  abcViewController.m
//  MapTest
//
//  Created by UEC on 21/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    manager = [[CLLocationManager alloc]init];
    manager.delegate = self;
    manager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    manager.distanceFilter = kCLDistanceFilterNone;
    
    [manager startUpdatingLocation];
    [manager startUpdatingHeading];

    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// Call at a set interval or a set distance

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    self.latLabel.text = [NSString stringWithFormat:@"%g",newLocation.coordinate.latitude];
    self.longLabel.text = [NSString stringWithFormat:@"%g",newLocation.coordinate.longitude];

    MKCoordinateRegion myregion = self.myMapView.region;
    myregion.center.latitude = newLocation.coordinate.latitude;
    myregion.center.longitude = newLocation.coordinate.longitude;
    myregion.span.latitudeDelta = 0.01;
    myregion.span.longitudeDelta = 0.01;
    [self.myMapView setRegion:myregion animated:YES];

}

@end

_____________________
WebView

_________________

//
//  abcViewController.m
//  WebView
//
//  Created by UEC on 21/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    NSURL *url = [NSURL URLWithString:@"http://www.yahoo.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.myWebView loadRequest:request];

    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

________________________

//
//  abcViewController.m
//  LoadImage
//
//  Created by UEC on 21/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    NSURL *url = [NSURL URLWithString:@"http://www.ymori.com/itest/test.jpg"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    self.myImageView.image = image;

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
____________________

//
//  abcViewController.m
//  ImageSelect
//
//  Created by UEC on 21/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)SelectCat:(id)sender {
    UIImage *image = [UIImage imageNamed:@"cat.png"];
    self.myImageView.image = image;
    
}

- (IBAction)SelectMonkey:(id)sender {
    UIImage *image = [UIImage imageNamed:@"monkey.png"];
    self.myImageView.image = image;
}

- (IBAction)SelectMouse:(id)sender {
    UIImage *image = [UIImage imageNamed:@"mouse.jpg"];
    self.myImageView.image = image;
}

- (IBAction)selectPlay:(id)sender {
    UIImage *i1 = [UIImage imageNamed:@"cat.png"];
       UIImage *i2 = [UIImage imageNamed:@"monkey.png"];
        UIImage *i3 = [UIImage imageNamed:@"mouse.jpg"];
    NSArray *images = [NSArray arrayWithObjects:i1,i2,i3,nil];
    
    self.myImageView.animationImages = images;
    self.myImageView.animationDuration = 1.0;
    self.myImageView.animationRepeatCount = 10;
    [self.myImageView startAnimating];

}
@end
______________

//
//  abcViewController.m
//  ImageSelect
//
//  Created by UEC on 21/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)SelectCat:(id)sender {
    UIImage *image = [UIImage imageNamed:@"cat.png"];
    self.myImageView.image = image;
    
}

- (IBAction)SelectMonkey:(id)sender {
    UIImage *image = [UIImage imageNamed:@"monkey.png"];
    self.myImageView.image = image;
}

- (IBAction)SelectMouse:(id)sender {
    UIImage *image = [UIImage imageNamed:@"mouse.jpg"];
    self.myImageView.image = image;
}

- (IBAction)selectPlay:(id)sender {
    UIImage *i1 = [UIImage imageNamed:@"cat.png"];
       UIImage *i2 = [UIImage imageNamed:@"monkey.png"];
        UIImage *i3 = [UIImage imageNamed:@"mouse.jpg"];
    NSArray *images = [NSArray arrayWithObjects:i1,i2,i3,nil];
    
    self.myImageView.animationImages = images;
    self.myImageView.animationDuration = 1.0;
    self.myImageView.animationRepeatCount = 10;
    [self.myImageView startAnimating];

}
@end
________________

//
//  abcViewController.m
//  ViewAnimation
//
//  Created by UEC on 21/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onStart:(id)sender {
    self.myLabel.center = CGPointMake(50, 50);
    
    // begin
    [UIView beginAnimations:nil context:nil];
    
    [UIView setAnimationDuration:2];
    self.myLabel.center = CGPointMake(160, 240);
    //Rotate it to 40 degre, need change radian
    self.myLabel.transform = CGAffineTransformMakeRotation(40*M_PI/180);
    // Scale up to point 30 and 20 points;
    self.myLabel.transform = CGAffineTransformMakeScale(30.0, 20.0);

    // end of animation
    [UIView commitAnimations];

    
}
@end

___________________________________

//
//  abcViewController.m
//  Timer
//
//  Created by UEC on 21/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "abcViewController.h"

@interface abcViewController ()

@end

@implementation abcViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(moveLabel:) userInfo:nil repeats:YES];

    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)moveLabel:(NSTimer *)timer {
    
    // x refer to hor location
    // y refer to ver location
    // Top Left is 0,0, Y down is +ve
    
    float wx = self.myLabel.center.x;
    float wy = self.myLabel.center.y;
    
    wx = wx + 5;
    wy = wy + 10;
    
    self.myLabel.center = CGPointMake(wx, wy);
}

@end