judaco / iPhone

0 stars 0 forks source link

iPhone - Class 08 #4

Open judaco opened 7 years ago

judaco commented 7 years ago
//
//  ViewController.m
//  Running TextView on iPhone 6
//
//  Created by hackeru on 10/05/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
    UITextView * textView;
    CGFloat x;
    CGFloat y;
    CGFloat width;
    CGFloat bottomMargin;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    x = 0;
    y = 30;
    width = self.view.frame.size.width;
    bottomMargin = 35;
    textView = [[UITextView alloc] initWithFrame:CGRectMake( x, y, width, self.view.frame.size.height - bottomMargin)];
    textView.text = @"some text ...";
    //textView.center = self.view.center;
    [self.view addSubview:textView];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:NSSelectorFromString(@"handleKeyboardDidShow") name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:NSSelectorFromString(@"handleKeyboardDidHide") name:UIKeyboardDidHideNotification object:nil];

}
-(void) removeObserver{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void) handleKeyboardDidShow:(NSNotification *) noftification{
    NSValue * value = notification.userInfo[UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardRect = CGRectZero;
    [value getValue:&keyboardRect];

    NSLog(@"keyboard did show %f", keyboardRect.size.height);

    textView.frame = CGRectMake(x, y, width, self.view.frame.size.height - bottomMargin - keyboardRect.size.height);
}
-(void) handleKeyboardDidHide:(NSNotification *) noftification{
    textView.frame = CGRectMake(x, y, width, self.view.frame.size.height - bottomMargin);

    NSLog(@"keyboard did hide");
}

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

@end
judaco commented 7 years ago
//
//  ViewController.m
//  UIScrollView
//
//  Created by hackeru on 10/05/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
        UIImage * img1;
        UIImageView * imageView;
        UIScrollView * scrollView;
}

- (void)viewDidLoad {
[super viewDidLoad];
    img1 = [UIImage imageNamed:@"img1"];
    imageView = [[UIImageView alloc] initWithImage:img1];
    imageView.frame = CGRectMake(0, 0, self.view.frame.size.width * 2, self.view.frame.size.height * 2);
    imageView.contentMode = UIViewContentModeScaleToFill;
    scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    [scrollView addSubview:imageView];
    scrollView.contentSize = imageView.frame.size;
    [self.view addSubview:imageView];
    scrollView.delegate = self;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    scrollView.alpha = 0.5;
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    scrollView.alpha = 1.0;
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    scrollView.alpha = 1.0;
}

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

@end
judaco commented 7 years ago
//
//  ViewController.m
//  UIWebView
//
//  Created by hackeru on 10/05/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
    {
        WKWebView * webView;
    }

- (void)viewDidLoad {
    [super viewDidLoad];

    WKPreferences * prefrences = [[WKPreferences alloc] init];
    prefrences.javaScriptEnabled = YES;
    WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc] init];
    configuration.preferences = prefrences;

    webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 35) configuration:configuration];
    NSURL * url = [[NSURL alloc] initWithString:@"http://www.cnn.com"];
    NSURLRequest * request = [[NSURLRequest alloc] initWithURL:url];
    [webView loadRequest:request];
    [self.view addSubview:webView];

    webView.navigationDelegate = self;

}

-(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

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

@end
judaco commented 7 years ago
//
//  ViewController.m
//  UIProgressView
//
//  Created by hackeru on 10/05/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
    {
        UIProgressView * progressView;
    }

- (void)viewDidLoad {
    [super viewDidLoad];
    progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
    progressView.center = self.view.center;
    progressView.progress = 0.5;
    progressView.trackTintColor = [UIColor greenColor];
    progressView.tintColor = [UIColor blueColor];
    [self.view addSubview:progressView];
}

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

@end
judaco commented 7 years ago
//
//  ViewController.m
//  TableView (ListView)
//
//  Created by hackeru on 10/05/2017.
//  Copyright © 2017 juda. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
    UITableView * tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    [tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"identifier"];
    [tableView.dataSource = self;
    [self.view addSubview:tableView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
 /*
 There's no need to implement numberOfSectionsInTableView: because there's only one section and the method defaults to returning 1.
 */

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"identifier" forIndexPath:indexPath];

/*
 Retrieve a cell with the given identifier from the table view.
 The cell is defined in the main storyboard: its identifier is MyIdentifier, and  its selection style is set to None.
 */
   UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];
   if(cell == nil){
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"identifier"];

   }else{

 }
// Set up the cell.
    cell.textLabel.text = [NSString stringWithFormat:@"Row %li", indexPath.row];
    return cell;  
}

-(BOOL)prefersStatusBarHidden{
    return YES;
}

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

@end