Friday, 24 June 2016

UIModelTransition in iOS - Objective C

1) Create single view application
2) Create FirstViewController and Secod View Controller classes
3) Design like following

4) Select first button, drag and drop to firstviewcontroller

5) Add class name to firstview controller  and second view controller

6) Select Segue change transition style to FlipHorizontal

7) Run the program

UIModelTransition in iOS - Objective C

1) Create single view application
2) Create FirstViewController and Secod View Controller classes
3) Design like following

4) Select first button, drag and drop to firstviewcontroller

5) Add class name to firstview controller  and second view controller

6) Select Segue change transition style to FlipHorizontal

7) Run the program

Custom Segue for UIViewAnimation in iOS - Objective C

1) Create a single view application
2) Select Main.StoryBoard
3) Design the interface by following



4) Click on "Go Next Button" -->Control drag towards Detail View -->Select Seque Name "Custom"

5) Create a new class named as "mysegue" which is going to be subclass of UIStoryBoardSegue
6) Go to StoryBoard select segue -->Open inspector select the class name "my segue"

7) Go to my segue class and implement a method called perform, for implementing custom animation with UIViewanimation

8) Reuse my segue class in application any where

Monday, 20 June 2016

Collection View Controller in iOS - Objective C

1) Create single view application
2) Select Story Board, delete existing view controller
3) Drag & Drop UICollectionViewController in to StoryBoard
4) Delete existing viewcontroller.h and viewcontroller.m
5) Add NewFile --> Enter new class name as mycollectionviewcontroller.h--> subclass of  UICollectionViewController
6) In Main.Storyboard add custom class

7) Select UICollectionview cell -->enter identifier as "Cell"

8) Drag & Drop Image view on UICollectionviewcell -->change Tag Value to "100"


9) Drag & drop Label on UICollectionview cell -->change Tag Value to "101"

10) Add below code in Mycollectionviewcontroller.h

@interface MyCollectionViewController : UICollectionViewController
{
    NSArray *devicePhotos;
    NSArray *deviceNameArr;
}

@end



11) Add below code in my controller.m
       1) Add below code in viewdidload

 devicePhotos=[[NSArray alloc]initWithObjects:@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg",@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg",@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg",nil];
    deviceNameArr=[[NSArray alloc]initWithObjects:@"iPhone",@"iPad",@"iPod",@"iPadmini", @"iPhone",@"iPad",@"iPod",@"iPadmini", @"iPhone",@"iPad",@"iPod",@"iPadmini", nil];


12) Add below methods in view controller.m

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return devicePhotos.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Cell";
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    // product Image
    UIImageView *iv = (UIImageView *)[cell viewWithTag:100];
    iv.image = [UIImage imageNamed:[devicePhotos objectAtIndex:indexPath.row]];
    // Product Name
    UILabel *lbl=(UILabel *)[cell viewWithTag:101];
    lbl.text=[deviceNameArr objectAtIndex:indexPath.row];
    
    return cell;

}

13) Build & Run the project

Reference: http://www.appcoda.com/ios-programming-uicollectionview-tutorial



Thursday, 16 June 2016

Navigation Controller in iOS - Objective C

1) create single view application
2) click on main.storyboard --> select view controller
3) go to Editor in menu --> EmbedIn --> navigation controller
4) select navigation controller scene, select navigator bar --> change attributes with customization like tint color,bar tint color,title color
5) go to main controller --> drag & drop two buttons
    1) Go to first view button
    2) Go to second view button
6) drag & drop two view controllers in to story board scene
7) Select Main view --> select first button -->control drag towards first controller--> connect segue name as show
8) do the same process for second view controller also
9) Add two UI View Controller subclasses in navigator window and configure them properly with view controller scenes
                                     How to configure 9th step
Select view controller, open identity inspector, Select drop down for the class name--->choose class

Wednesday, 15 June 2016

UIScroll View in iOS - Objective C

1) create single view application
2) Add below code in view controller.h

@interface ViewController : UIViewController
{
    UIScrollView *scrollView;
}

@end


3) Add below code in view controller.m

- (void)viewDidLoad {
    scrollView=[[UIScrollView alloc]init];
    scrollView.frame=self.view.bounds;
    
    scrollView.contentSize=CGSizeMake(self.view.frame.size.width, self.view.frame.size.height*3);
    scrollView.backgroundColor=[UIColor grayColor];
    [self.view addSubview:scrollView];
    
    UIImageView *img1=[[UIImageView alloc]init];
    img1.frame=CGRectMake(10, 40, 300, 400);
    img1.image=[UIImage imageNamed:@"1.jpeg"];
    [scrollView addSubview:img1];
    
    UIImageView *img2=[[UIImageView alloc]init];
    img2.frame=CGRectMake(10, 480, 300, 400);
    img2.image=[UIImage imageNamed:@"2.jpeg"];
    [scrollView addSubview:img2];
    
    UIImageView *img3=[[UIImageView alloc]init];
    img3.frame=CGRectMake(10, 920, 300, 400);
    img3.image=[UIImage imageNamed:@"3.jpeg"];
    [scrollView addSubview:img3];
    
    
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

}


Image View with Array of Images in iOS - Objective C

1) Create Single View Application
2) Go to ViewController.h, Add below code

@interface ViewController : UIViewController
{
   UIImageView *imgView;
    
}

@end



3) Go to view controller.m  Add below code

- (void)viewDidLoad
{
    
    imgView=[[UIImageView alloc]init];
    imgView.frame=CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height/2 );
    NSArray *imgArray=[NSArray arrayWithObjects:
                       [UIImage imageNamed:@"1.jpeg"],
                       [UIImage imageNamed:@"2.jpeg"],
                       [UIImage imageNamed:@"3.jpeg"],
                       [UIImage imageNamed:@"4.jpeg"],
                       nil];
    imgView.animationImages=imgArray;
    imgView.animationDuration=4.0;
    imgView.animationRepeatCount=0;
    [imgView startAnimating];
    [self.view addSubview:imgView];
    
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}



TableView Controller - Use Case3 - in iOS - Objective C

Use Case3
       |
Main
       |
UI Table View Controller
      |
UI Table View
      |
UI Table View Cell (wrong X)
      |
Custom Cell
      |
Custom Components
=============================
1) Implement Use Case1 as it is
2) Right click on table controller have a new file, iOS source cocoa touch class
3) Click next button, class name "MyCell", SubClass of UITableViewCell
4) Use checkmark also create Xib File, click on next
5) go to MyCell.Xib design following
     1) Product Name  -- Label
     2) Product Price   -- Label'
     3) Description      -- Label
     4) Image               -- Image View
6) Go to MyCell.h and implement following custom properties

@property (weak, nonatomic) IBOutlet UILabel *prdName;
@property (weak, nonatomic) IBOutlet UILabel *prdPrice;
@property (weak, nonatomic) IBOutlet UILabel *prdDes;
@property (weak, nonatomic) IBOutlet UIImageView *prdImage;


7) Go to tableviewcontroller, import MyCell.h
    #import "mycell.h"

8) Go to controller.m and go to method "CellForRowAtIndexPath" and remove the code of default cell, implement custom cell by following
- (void)viewDidLoad {
    
    idevices=[NSArray arrayWithObjects:@"iPhone",@"iPad",@"iPod",@"iPadmini", nil];
    androidDevices=[NSArray arrayWithObjects:@"HTC",@"samsung",@"Lenevo",@"Nexus", nil];
    
    idevicesImg=[NSArray arrayWithObjects:@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg", nil];
    andImg=[NSArray arrayWithObjects:@"11.png",@"22.png",@"33.jpeg",@"44.jpeg", nil];

    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

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

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return 5;
    if (section==0) {
        return idevices.count;
    }
    else
    {
        return androidDevices.count;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
//    // Configure the cell...
//   // cell.textLabel.text=@"Hello iOS SDK";
//    if (indexPath.section==0) {
//        cell.textLabel.text=[idevices objectAtIndex:indexPath.row];
//    }
//    else
//    {
//        cell.textLabel.text=[androidDevices objectAtIndex:indexPath.row];
//    }
    
      static NSString *simpleTableIdentifier = @"MyCellID";
    MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    // Configure Properties
    if (indexPath.section==0) {
        cell.prdName.text=[idevices objectAtIndex:indexPath.row];
        cell.prdPrice.text=@"20000";
        cell.prdDes.text=@"This is an apple device";
        cell.prdImage.image=[UIImage imageNamed:[idevicesImg objectAtIndex:indexPath.row]];
    }
    else{
        cell.prdName.text=[androidDevices objectAtIndex:indexPath.row];
        cell.prdPrice.text=@"10000";
        cell.prdDes.text=@"This is an Android device";
//        NSLog(@"height is %f", cell.prdImage.frame.size.width);
//        cell.prdImage.frame.size.width== cell.prdImage.frame.size.width-30;
//        NSLog(@"height is %f", cell.prdImage.frame.size.width);
//
        cell.prdImage.image=[UIImage imageNamed:[andImg objectAtIndex:indexPath.row]];
        
    }
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 115.0;
}





9) MyCell.Xib ---> Select CustomCell ---->identifier as "MyCellID"



10)
11) Build and Run the Application


Tuesday, 14 June 2016

Table View Controller - Use Case 2 - in iOS Objective C

Use Case - 2
        |
     Main
        |
UI View Controller
        |
UI View
        |
UITableView
        |
UITable View Cell
       |
UI Components
==================
1) Create Single View Application
2) Drag & Drop Table View on UiView Controller

3) Drag & Drop Table View Cell  on Table View

4) InViewController.h file write below code

@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
    IBOutlet UITableView *tableObj;
    NSArray *idevices,*androidDevices;
    NSString *mess;
}

@end





5) In ViewController.m write below code
- (void)viewDidLoad {
    
    tableObj.dataSource=self;
    tableObj.delegate=self;
    
  
    idevices=[NSArray arrayWithObjects:@"iPhone",@"iPad",@"iPod",@"iPadmini", nil];
    androidDevices=[NSArray arrayWithObjects:@"HTC",@"samsung",@"Lenevo",@"Nexus", nil];
    
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return 5;
    if (section==0) {
        return idevices.count;
    }
    else
    {
        return androidDevices.count;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
    // Configure the cell...
    // cell.textLabel.text=@"Hello iOS SDK";
    cell.textLabel.textAlignment=NSTextAlignmentCenter;
    cell.textLabel.font=[UIFont fontWithName:@"Verdana" size:26];
    cell.textLabel.textColor=[UIColor blueColor];
  //  cell.backgroundColor=[UIColor yellowColor];
//    cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.jpg"]];
    
    if (indexPath.section==0) {
        cell.textLabel.text=[idevices objectAtIndex:indexPath.row];
    }
    else
    {
        cell.textLabel.text=[androidDevices objectAtIndex:indexPath.row];
    }
    return cell;
}
// delegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        mess=[NSString stringWithFormat:@"you liked..%@",[idevices objectAtIndex:indexPath.row]];
    }
    else
    {
           mess=[NSString stringWithFormat:@"you liked..%@",[androidDevices objectAtIndex:indexPath.row]];
    }
     UIAlertController * alert=   [UIAlertController
                                      alertControllerWithTitle:@"Hello User"
                                      message:mess
                                      preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* ok = [UIAlertAction
                             actionWithTitle:@"OK"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 [alert dismissViewControllerAnimated:YES completion:nil];
                                 // navigation for another controller
                                 
                             }];
        UIAlertAction* cancel = [UIAlertAction
                                 actionWithTitle:@"Cancel"
                                 style:UIAlertActionStyleDefault
                                 handler:^(UIAlertAction * action)
                                 {
                                     [alert dismissViewControllerAnimated:YES completion:nil];
                                     
                                 }];
        
        [alert addAction:ok];
        [alert addAction:cancel];
        
        [self presentViewController:alert animated:YES completion:nil];

}

6) Right Click on Table View --> Map referencing outlet to tableObj

7) Click on Table Cell -->Identifier-->MyCell

8) Build & Run Application

Table View Controller - UseCase 1 - in iOS - Objective C

USE CASE-1
        |
Main
   |
UITableView Controller
   |
UITableView
   |
UITableViewCell
    |
UIComponents
=============

1) Create Single View Application
2) Go to Main.StoryBoard, delete existing viewcontroller scene and delete referencing class also
3) Add a tableviewcontroller scene in main.storyboard and add referencing class also in navigator, which is going to be subclass of UITableViewController




4) Click on TableViewController scene, go to property inspector choose checkmark use "initialviewcontroller" (This is configuration of storyboard entry point)


5) go to tableviewcontroller.m implement datasource methods



 idevices=[NSArray arrayWithObjects:@"iPhone",@"iPad",@"iPod",@"iPadmini", nil];
 androidDevices=[NSArray arrayWithObjects:@"HTC",@"Samsung",@"Nexus",@"Lenovo", nil];




#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return 5;
    if (section==0) {
        return idevices.count;
    }
    else
    {
        return androidDevices.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell" forIndexPath:indexPath];
    // Configure the cell...
    // cell.textLabel.text=@"Hello iOS SDK";
    if (indexPath.section==0) {
        cell.textLabel.text=[idevices objectAtIndex:indexPath.row];
    }
    else
    {
        cell.textLabel.text=[androidDevices objectAtIndex:indexPath.row];
    }
    return cell;

}


6) go to CellforRowAtIndexPath method and provide identifier value as string "MyCell"
7) Go to StoryBoard Select Your Cell, Open Inspector and provide identifier name

8) Build and run Application

Monday, 13 June 2016

UIPickerview in iOS - Objective C

1) Drag & Drop UIPickerview and UILabel in to StoryBoard

2) Add Datasource and Delegate Protocols in view controller.h

@interface ViewController : UIViewController <UIPickerViewDelegate,UIPickerViewDataSource>

3) Declare A property in view controller.h 

@property(strong,nonatomic) NSArray *dataSourceArray;

4) Drag & Drop, Datasource and Delegate to ViewController

5) Right Click UIPickerview, Select referencing outlet, drag&drop to view controller.h, name it as picker
6) Right Click Label, Select referencing outlet, drag&drop to view controller.h, name it as resultLabel



7) Add below code in view controller.m

8) Reference Website: http://ioseducation.org/example-use-uipickerview/

http://ioseducation.org/example-use-uipickerview/








Friday, 10 June 2016

create label and button through code in iOS - Objective C

1) Add below code in viewcontroller.h

UILabel *labelObj;

UIButton *butObj;


2) Add below code view controller.m