judaco / iPhone

0 stars 0 forks source link

iPhone - Class 05 #2

Open judaco opened 7 years ago

judaco commented 7 years ago

Alerts

//
//  ViewController.m
//  Alert
//
//  Created by hackeru on 26/04/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
    UIAlertAction * action;
}

- (void)viewDidLoad {
    [super viewDidLoad];

}

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

    //[self alert:@"yalla bye"];

//    UIAlertController * controller = [UIAlertController alertControllerWithTitle:@"username" message:@"plesae enter use name" preferredStyle:UIAlertControllerStyleAlert];
//    
//    [controller addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
//        textField.placeholder = @"user name";
//    }];
//    
//    UIAlertAction * action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        NSString * valueOfTextField = controller.textFields[0].text;
//        NSLog(@"button clicked %@", valueOfTextField);
//    }];
//    [controller addAction: action];
//    [self presentViewController:controller animated:YES completion:nil];

    controller  = [UIAlertController alertControllerWithTitle:@"choose what to do with the image" message:@"warning: deleted photo cannot be resotred" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction * actionShare =
}

-(void)alert:(NSString*)msg{
    UIAlertController * controller = [UIAlertController alertControllerWithTitle:@"alert" message:msg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDestructive handler:nil];
    [controller addAction:action];
    [self presentViewController:controller animated:YES completion:nil];
}

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

@end
judaco commented 7 years ago

Switch Button (CheckBox)

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
    UISwitch * mSwitch;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    mSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 0, 0)];
    [self.view addSubview:mSwitch];
    [mSwitch setOn:YES animated:NO];

    [mSwitch addTarget:self action:NSSelectorFromString(@"switchChanged:") forControlEvents:UIControlEventValueChanged];
    mSwitch.tintColor = [UIColor redColor];
    mSwitch.onTintColor = [UIColor greenColor];
    mSwitch.thumbTintColor = [UIColor blueColor];
}

-(void)switchChanged: (UISwitch*) sender{
    if (sender == mSwitch) {
        //true
    }
    if (sender.on) {
        NSLog(@"switch is on");
    }else{
        NSLog(@"switch is off");
    }
}

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

@end
judaco commented 7 years ago

PickerView (Toggle)

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
    UIPickerView * picker;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    picker = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 10, 200, 300)];
    [self.view addSubview:picker];
    picker.dataSource = self;
    picker.delegate = self;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 2;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if(component == 0)
        return 10;
    else
        return 20;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component == 0)
        return [[NSString alloc] initWithFormat:@"row %li", (row+1)];
    else
        return [[NSString alloc] initWithFormat:@"row %li", (row +11)];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSLog(@"row %li component %li", row, component);
}

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

@end