nuclear  zone  productions  
                                Source Code Samples
cache/wst.opf.4309039.xml


    MENU      < Some Source Code Is Written Pre IOS 5 >



       Calculations 
                CG Graphics 
                            UI Idiom
                                    Loops
                                          Color Info
                                                   User Interface Controls
                                                     UI Controls CGRect
                                                              Main Function - IOS / Objective C

                                                                                                  App Delegate
                                                                                                           UITableView
                                                                                                                    UIPickerView - Programmatic
                                                                                                                                   UIView - SubViews
                                                                                                                                   Display Message - NSString / UIButton
                                                                                                                                   Display Image - UIButton
                                                                                                                   Saving Data - NSUser Defaults
                                                                                               Page Switch - XIB File - Protocol / Delegation
                                                                                        UISlider
                                                    Create Class - Setter / Getter
                                                    Create Class - Properties

                        


                          Most Sections / Controllers .h and .m Are Shown In Full.


  Calculations Samples In IOS (Objective C) 
 
 
h

 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController

 @property (strong, nonatomic) IBOutlet UILabel *label;

 - (IBAction)calculate:(id)sender;

 @end

 m
 #import "ViewController.h"

 @interface ViewController ()

 @end

 @implementation ViewController

 @synthesize label = _label;

 - (IBAction)calculate:(id)sender

 {

int x;

x = 10;

int y;

y = 5;

int sum;

sum = x + y;

NSLog(@"%d", sum);

int x1 = 10;

int y1 = 5;

int result;

result = x1 - y1;

NSLog(@"%d", result);

result ++;

NSLog(@"%d", result);

result --;

NSLog(@"%d", result);

int a = 200;

int b = 100;

float output;

output = a / b;

NSLog(@"%.0f", output);

if (output == 2) {

self.label.text = @"2";

NSLog(@"result is : %.4f", output);

 }

else{

self.label.text = @"error";

NSLog(@"error");

}

        NSInteger a1 = 10;

        NSInteger b1 = 10;

float finalNumber;

finalNumber = a1 * b1;

NSLog(@"%.2f", finalNumber);

int count;

count = 0;

count = count + 1;

count = count + 1;

count = count + 1;

count = count + 1;

count = count + 1;

NSLog(@"%i", count);

int count1;

count1 = 0;

count1 = count1 - 1;

count1 = count1 - 1;

count1 = count1 - 1;

count1 = count1 - 1;

count1 = count1 - 1;

count1 = count1 - 1;

NSLog(@"%i", count1);

int number1 = 1000;

int number2 = 2000;

int productOfTheseNumbers (int number1, int number2);

int result1;

result1 = number1 * number2;

NSLog(@"%i", result1);

if (result1 < 3000000) {

NSLog(@"result is less than 3000000");

}

else{

if (result1 > 3000000) {

NSLog(@"result is more than 3000000");

}

}

 }

 - (void)viewDidLoad

 {

    [super viewDidLoad];

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];

 }

 @end

   CG Graphics Samples  
 AppDeledate.h

 #import <UIKit/UIKit.h>
 @class ViewController;
 @interface AppDelegate : UIResponder <UIApplicationDelegate>
 @property (strong, nonatomic) UIWindow *window;
 @property (strong, nonatomic) IBOutlet ViewController *viewController;
 @end
  AppDelegate.m

 #import "AppDelegate.h"
 #import "ViewController.h"
 @implementation AppDelegate

 @synthesize viewController = _viewController; 

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

  {
      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
      self.window.backgroundColor = [UIColor whiteColor];
      self.window.rootViewController = self.viewController;
      [self.window makeKeyAndVisible];
      return YES;
   }
 - (void)applicationWillResignActive:(UIApplication *)application
 {
 }
 - (void)applicationDidEnterBackground:(UIApplication *)application
 {
 }
 - (void)applicationWillEnterForeground:(UIApplication *)application
 {
 }
 - (void)applicationDidBecomeActive:(UIApplication *)application
 {
 }
 - (void)applicationWillTerminate:(UIApplication *)application
 {
 }
 @end
  ViewController.h

 #import <UIKit/UIKit.h>
 #import "MainView.h"
 @interface ViewController : UIViewController
 @property (nonatomic, strong) MainView *mainView;
 @end
  ViewController.m

 #import "ViewController.h"

 @interface ViewController ()

 @end

 @implementation ViewController

 @synthesize mainView;

 - (MainView *)mainView

 {

     if (!mainView) {

          self.mainView = [[MainView alloc] initWithFrame:[self.view frame]];

     }

     return mainView;

 }

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

 {

     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

     if (self) {

         self.view = self.mainView;

     }

     return self;

 }

 - (void)viewDidLoad

 {

     [super viewDidLoad];

 }

 - (void)didReceiveMemoryWarning

 {

     [super didReceiveMemoryWarning];

 }

 @end
  MainView.h

 #import <UIKit/UIKit.h>

 @interface MainView : UIView

 @end
  MainView.m
 - (void)drawRect:(CGRect)rect

 {   

    // Drawing Code .. Rectangle.

    CGContextRef context = UIGraphicsGetCurrentContext();            

    CGContextSetLineWidth(context, 3.5);                             

    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0);        

    CGContextMoveToPoint(context, 10, 10);                           

    CGContextAddLineToPoint(context, 310, 10);                     

    CGContextAddLineToPoint(context, 310, 50);                       

    CGContextAddLineToPoint(context, 10, 50);                        

    CGContextClosePath(context);                                    

    CGContextStrokePath(context);

    // Drawing Code .. Filled Rectangle.

    CGContextSetRGBFillColor(context, 1.0, 1.0, 0.0, 1.0);

    CGContextMoveToPoint(context, 20, 20); 

    CGContextAddLineToPoint(context, 300, 20);                      

    CGContextAddLineToPoint(context, 300, 40);                       

    CGContextAddLineToPoint(context, 20, 40);                       

    CGContextClosePath(context);                                    

    CGContextFillPath(context);

    // Drawing Code .. Triangle.

    CGContextSetLineWidth(context, 4.25);

    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0.0, 1.0);           

    CGContextMoveToPoint(context, 202.15, 150);                          

    CGContextAddLineToPoint(context, 299.85, 63.15);                       

    CGContextAddLineToPoint(context, 202.15, 207.35);                     

    CGContextClosePath(context);                                

    CGContextStrokePath(context);

    // Drawing Code .. Square.

    CGContextSetLineWidth(context, 8.55);

    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);

    CGContextMoveToPoint(context, 50, 100);

    CGContextAddLineToPoint(context, 150, 100);

    CGContextAddLineToPoint(context, 150, 200);

    CGContextAddLineToPoint(context, 50, 200);    

    CGContextClosePath(context);                  

    CGContextStrokePath(context);              

    // Drawing Code .. Black Square.

    CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);

    CGContextMoveToPoint(context, 120, 150);

    CGContextAddLineToPoint(context, 200, 150);

    CGContextAddLineToPoint(context, 200, 250);

    CGContextAddLineToPoint(context, 120, 250);   

    CGContextClosePath(context);

    CGContextFillPath(context);

    // Drawing Code .. Square.

    CGContextSetLineWidth(context, 4.25);

    CGContextSetRGBStrokeColor(context, 1.0, 0.5, 0.0, 1.0);

    CGContextMoveToPoint(context, 50, 210);

    CGContextAddLineToPoint(context, 250, 210);

    CGContextAddLineToPoint(context, 250, 400);

    CGContextAddLineToPoint(context, 50, 400);    

    CGContextClosePath(context);                   

    CGContextStrokePath(context);                  

    //CGContextAddArc(<#CGContextRef c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>,                                                   <#CGFloat endAngle#>, <#int clockwise#>)
    // Partial 3/4 Arc Within Square.

    CGContextSetLineWidth(context, 3.05);                        

    CGContextSetRGBStrokeColor(context, 0.0, 0.33, 1.0, 1.0);     

    CGContextAddArc(context, 150, 305, 88,(3*M_PI)/2, M_PI, 0);   

    CGContextStrokePath(context);                                                          //Partially Filled Circle Within Arc.                         

    CGContextSetRGBFillColor(context, 0.67, 0.84, 0.00, 1.0);

    CGContextAddArc(context, 150, 305, 87, 10, 2*M_PI, 1);        

    CGContextFillPath(context);

    // Full Filled Circle Within Arc, Within Partial Circle.

    CGContextSetRGBFillColor(context, 1.00, 0.89, 0.27, 1.0);  

    CGContextAddArc(context, 150, 305, 40, 0, 2*M_PI, 1);

    CGContextFillPath(context);

 }

   
 

 #import "MainView.h"
 @implementation MainView
 - (id)initWithFrame:(CGRect)frame
 {
      self = [super initWithFrame:frame];
  if (self) {
              self.backgroundColor = [UIColor blackColor];
     }
      return self;
 }
 - (void)drawRect:(CGRect)rect
 {
     CGContextRef context = UIGraphicsGetCurrentContext();            
     CGContextSetLineWidth(context, 20.2);
     CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 0.0, 0.0);
     CGContextAddLineToPoint(context, 0.0, 460.0);
     CGContextAddLineToPoint(context, 310.0, 460.0);
     CGContextAddLineToPoint(context, 310.0, 0.0);
     CGContextClosePath(context);                                    
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 20.2, 20.2);
     CGContextAddLineToPoint(context, 20.2, 439.8);
     CGContextAddLineToPoint(context, 289.8, 439.8);
     CGContextAddLineToPoint(context, 289.8, 20.2);
     CGContextClosePath(context);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 0.0, 1.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 40.4, 40.4);
     CGContextAddLineToPoint(context, 269.6, 419.6);
     CGContextAddLineToPoint(context, 269.6, 40.4);
     CGContextClosePath(context);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
     CGContextMoveToPoint(context, 60.6, 51.6);
     CGContextAddLineToPoint(context, 60.6, 409.4);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
     CGContextMoveToPoint(context, 51.6, 399.4);
     CGContextAddLineToPoint(context, 258.6, 399.4);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 0.9, 1.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 249.6, 409.4);
     CGContextAddLineToPoint(context, 249.6, 50.6);
     CGContextStrokePath(context);
     CGContextSetLineWidth(context, 22.2);
     CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 258.6, 61.5);
     CGContextAddLineToPoint(context, 50.8, 61.5);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 79.9, 71.5);
     CGContextAddLineToPoint(context, 79.9, 378.9);
     CGContextAddLineToPoint(context, 239.5, 378.9);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 0.9, 1.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 100.1, 71.4);
     CGContextAddLineToPoint(context, 100.1, 358.7);
     CGContextAddLineToPoint(context, 240.7, 358.7);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 0.9, 1.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 100.1, 75.25);
     CGContextAddLineToPoint(context, 100.1, 358.7);
     CGContextAddLineToPoint(context, 240.7, 358.7);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 0.9, 1.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 100.1, 82.45);
     CGContextAddLineToPoint(context, 258.1, 82.45);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 120.3, 93.25);
     CGContextAddLineToPoint(context, 120.3, 338.5);
     CGContextAddLineToPoint(context, 240.7, 338.5);
     CGContextStrokePath(context);
     CGContextSetRGBStrokeColor(context, 0.0, 1.0, 0.0, 1.0);
     CGContextMoveToPoint(context, 140.5, 30.25);
     CGContextAddLineToPoint(context, 140.5, 318.3);
     CGContextAddLineToPoint(context, 260.7, 318.3);
     CGContextStrokePath(context);
 }
 @end

  
  ViewController.h   

 #import <UIKit/UIKit.h>

 #import "GraphView.h"

 @interface ViewController : UIViewController

 @property (nonatomic, strong) IBOutlet GraphView *graphView;

 @end

  ViewController.m
 #import "ViewController.h"    

 @interface ViewController ()

 @end

 @implementation ViewController

 @synthesize graphView = _graphView;

 - (void)viewDidLoad

 {

     [super viewDidLoad];

      self.graphView = [[GraphView alloc] initWithFrame:self.graphView.frame];

 }

 - (void)didReceiveMemoryWarning

 {

     [super didReceiveMemoryWarning];

 }

 @end

  GraphView.h
 #import <UIKit/UIKit.h>   

 @interface GraphView : UIView

 @end

  GraphView.m

 #import "GraphView.h"

 @implementation GraphView

 - (id)initWithFrame:(CGRect)frame

 {

     self = [super initWithFrame:frame];

     if (self) {

     }

     return self;

 }

 - (void)drawAxes

 {

     CGFloat x, y;

     x = self.bounds.size.width / 2;

     y = self.bounds.size.height / 2;

     CGContextRef context = UIGraphicsGetCurrentContext();

     CGAffineTransform contentTransformMatrix = CGContextGetCTM(context);

     CGAffineTransformScale(contentTransformMatrix, 1.0, -1.0);

     CGContextConcatCTM(context, contentTransformMatrix);

     CGContextTranslateCTM(context, x, y);

     CGContextSetLineWidth(context, 1.5);

     CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);

     CGContextMoveToPoint(context, 0, -y);

     CGContextAddLineToPoint(context, 0, y);

     CGContextMoveToPoint(context, -x, 0);

     CGContextAddLineToPoint(context, x, 0);

     for (float f = -360; f <= 360; f += 20) {

         CGContextMoveToPoint(context, f, 10);

         CGContextAddLineToPoint(context, f, -10);

         CGContextMoveToPoint(context, 10, f);

         CGContextAddLineToPoint(context, -10, f);

     }  

     CGContextStrokePath(context);

 }

 - (void)drawRect:(CGRect)rect

 {

     [self drawAxes];

     CGContextRef context = UIGraphicsGetCurrentContext();

     CGContextSetLineWidth(context, 0.0);

     CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);

     float y;

     for (float x = -364; x <= 364; x += 0.05f) {

         y = 300 * sinf(x / 20);

         y = (x * x) / 200;

         y = 1 * x + 60;

         CGContextFillRect(context, CGRectMake(x, y, 2.8, 2.8));

     }

 CGContextRef context1 = UIGraphicsGetCurrentContext();

     CGContextSetLineWidth(context1, 0.0);

     CGContextSetRGBFillColor(context1, 0.0, 0.0, 1.0, 1.0);

     float y1;

     for (float x = -364; x <= 364; x += 0.05f) {

         y1 = 300 * sinf(x / 20);

         y1 = (x * x) / 200;

         CGContextFillRect(context1, CGRectMake(x, y1, 1.8, 1.8));

     }

 CGContextRef context2 = UIGraphicsGetCurrentContext();

     CGContextSetLineWidth(context2, 0.0);

     CGContextSetRGBFillColor(context2, 0.0, 1.0, 0.0, 1.0);

     float y2;

     for (float x = -364; x <= 364; x += 0.05f) {

         y2 = 300 * sinf(x / 20);

         CGContextFillRect(context2, CGRectMake(x, y2, 2.2, 1.8));

     }

 }

 @end


     

 #import "GraphView.h"

 @implementation GraphView

 - (id)initWithFrame:(CGRect)frame

 {

    self = [super initWithFrame:frame];

    if (self) {

    }

    return self;

 }

 - (void)drawAxes

 {

    CGFloat x, y;

    x = self.bounds.size.width / 2;

    y = self.bounds.size.height / 2;

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGAffineTransform contentTransformMatrix = CGContextGetCTM(context);

    CGAffineTransformScale(contentTransformMatrix, 1.0, -1.0);

    CGContextConcatCTM(context, contentTransformMatrix);

    CGContextTranslateCTM(context, x, y);

    CGContextSetLineWidth(context, 1.5);

    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);

    CGContextMoveToPoint(context, 0, -y);

    CGContextAddLineToPoint(context, 0, y);

    CGContextMoveToPoint(context, -x, 0);

    CGContextAddLineToPoint(context, x, 0);

    for (float f = -360; f <= 360; f += 20) {

        CGContextMoveToPoint(context, f, 10);

        CGContextAddLineToPoint(context, f, -10);

        CGContextMoveToPoint(context, 10, f);

        CGContextAddLineToPoint(context, -10, f);

    }  

    CGContextStrokePath(context);

 }

 - (void)drawRect:(CGRect)rect

 {

    [self drawAxes];

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 0.0);

    CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);

    float y;

    for (float x = -364; x <= 364; x += 0.05f) {

        y = 300 * sinf(y / 20);

        y = (x * y) / 200;

        y = 1 * y + 60;

        CGContextFillRect(context, CGRectMake(x, y, 2.8, 2.8));

    }

}

 @end

     
 

 #import "GraphView.h"

 @implementation GraphView

 - (id)initWithFrame:(CGRect)frame

 {

    self = [super initWithFrame:frame];

    if (self) {

    }

    return self;

 }

 - (void)drawAxes

 {

    CGFloat x, y;

    x = self.bounds.size.width / 2;

    y = self.bounds.size.height / 2;

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGAffineTransform contentTransformMatrix = CGContextGetCTM(context);

    CGAffineTransformScale(contentTransformMatrix, 1.0, -1.0);

    CGContextConcatCTM(context, contentTransformMatrix);

    CGContextTranslateCTM(context, x, y);

    CGContextSetLineWidth(context, 1.5);

    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);

    CGContextMoveToPoint(context, 0, -y);

    CGContextAddLineToPoint(context, 0, y);

    CGContextMoveToPoint(context, -x, 0);

    CGContextAddLineToPoint(context, x, 0);

    for (float f = -360; f <= 360; f += 20) {

        CGContextMoveToPoint(context, f, 10);

        CGContextAddLineToPoint(context, f, -10);

        CGContextMoveToPoint(context, 10, f);

        CGContextAddLineToPoint(context, -10, f);

    }  

    CGContextStrokePath(context);

 }

 - (void)drawRect:(CGRect)rect

 {

    [self drawAxes];

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 0.0);

    CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);

    float y;

    for (float x = -364; x <= 364; x += 0.05f) {

        y = 30 * sinf(x * 20);

    CGContextFillRect(context, CGRectMake(x, y, 2.8, 1.8));

 }

    CGContextRef context1 = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context1, 0.0);

    CGContextSetRGBFillColor(context1, 1.0, 0.0, 0.0, 1.0);

    float y1;

    for (float x = -364; x <= 364; x += 0.05f) {

        y1 = 300 * sinf(x * 20);

CGContextFillRect(context1, CGRectMake(x, y1, 2.8, 1.8));

   }

 }

 @end

     

 #import "GraphView.h"

 @implementation GraphView

 - (id)initWithFrame:(CGRect)frame

 {

    self = [super initWithFrame:frame];

    if (self) {

    }

    return self;

 }

 - (void)drawAxes

 {

    CGFloat x, y;

    x = self.bounds.size.width / 2;

    y = self.bounds.size.height / 2;

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGAffineTransform contentTransformMatrix = CGContextGetCTM(context);

    CGAffineTransformScale(contentTransformMatrix, 1.0, -1.0);

    CGContextConcatCTM(context, contentTransformMatrix);

    CGContextTranslateCTM(context, x, y);

    CGContextSetLineWidth(context, 1.5);

    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);

    CGContextMoveToPoint(context, 0, -y);

    CGContextAddLineToPoint(context, 0, y);

    CGContextMoveToPoint(context, -x, 0);

    CGContextAddLineToPoint(context, x, 0);

    for (float f = -360; f <= 360; f += 20) {

        CGContextMoveToPoint(context, f, 10);

        CGContextAddLineToPoint(context, f, -10);

        CGContextMoveToPoint(context, 10, f);

        CGContextAddLineToPoint(context, -10, f);

    }  

    CGContextStrokePath(context);

 }

 - (void)drawRect:(CGRect)rect

 {

    [self drawAxes];

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 0.0);

    CGContextSetRGBFillColor(context, 1.0, 0.0, 1.0, 1.0);

    float y;

    for (float x = -364; x <= 364; x += 0.05f) {

        y = 3 * sinf(x / 2000);

CGContextFillRect(context, CGRectMake(x, y, 2.8, 1.8));

 }

CGContextRef context1 = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 0.0);

    CGContextSetRGBFillColor(context1, 1.0, 0.0, 1.0, 1.0);

    float y1;

    for (float x = -364; x <= 364; x += 0.05f) {

        y1 = 3 * sinf(x / 1);

y1 = (x * x) / 200;

y1 = 1 * y + 60;

CGContextFillRect(context1, CGRectMake(x, y1, 2.8, 1.8));

 }

CGContextRef context2 = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context2, 0.0);

    CGContextSetRGBFillColor(context2, 1.0, 0.0, 0.0, 1.0);

    float y2;

    for (float x = -364; x <= 364; x += 0.05f) {

        y2 = 3000 * sinf(x / 20);

CGContextFillRect(context2, CGRectMake(x, y2, 2.8, 1.8));

 }

CGContextRef context3 = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context3, 0.0);

    CGContextSetRGBFillColor(context3, 0.0, 1.0, 0.0, 1.0);

    float y3;

    for (float x = -364; x <= 364; x += 0.05f) {

        y3 = 3000 * sinf(x / 20) / 10;

CGContextFillRect(context3, CGRectMake(x, y3, 2.8, 1.8));

 }

CGContextRef context4 = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context4, 0.0);

    CGContextSetRGBFillColor(context4, 1.0, 0.0, 0.0, 1.0);

    float y4;

    for (float x = -364; x <= 364; x += 0.05f) {

        y4 = 300 * sinf(x / 20) /10;

CGContextFillRect(context4, CGRectMake(x, y4, 2.8, 1.8));

}

 }

 @end

      


     UI Idiom  

 #import "AppDelegate.h"
 #import "ViewController.h"
 @implementation AppDelegate
 @synthesize viewController = _viewController;
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 
{
       self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
       if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
 }else{
       self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
 }
       self.window.backgroundColor = [UIColor whiteColor];
       self.window.rootViewController = self.viewController;
      [self.window makeKeyAndVisible];
       return YES;
 }
 - (void)applicationWillResignActive:(UIApplication *)application
 {
 }
 - (void)applicationDidEnterBackground:(UIApplication *)application
 {
 }
 - (void)applicationWillEnterForeground:(UIApplication *)application
 {
 }
 - (void)applicationDidBecomeActive:(UIApplication *)application
 {
 }
 - (void)applicationWillTerminate:(UIApplication *)application
 {
 }
 @end


  

 - (void) MainViewControllerDidFinish:(MainViewController *)controller

 {

[self dismissViewControllerAnimated:YES completion:nil];

 }

 - (IBAction)mainPage:(id)sender

 {

if ([[UIDevice currentDevice ] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil];

controller.delegate = self;

controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:controller animated:YES completion:nil];

}else{

MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController_iPad" bundle:nil];

controller.delegate = self;

controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:controller animated:YES completion:nil];

     }

 }


 - (void)viewDidLoad
 {
        [super viewDidLoad];
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"File A1" ofType:@"txt"];
        if (filePath) {
        NSString *text = [NSString stringWithContentsOfFile:filePath encoding:NSISOLatin1StringEncoding error:nil];
        if (text)
 {        self.textView= [[UITextView alloc] initWithFrame:CGRectMake(0,5,280,490)];
          self.textView.text = text;
         [self.textView setFont:[UIFont systemFontOfSize:12]];
         [self.textView setBackgroundColor:[UIColor clearColor]];
         [self.textView setTextColor:[UIColor blackColor]];
          self.textView.editable = NO;
          self.textView.dataDetectorTypes = UIDataDetectorTypeNone;
         [self.scroll addSubview:self.textView];
    }
 }
    }else{
       NSString *filePath = [[NSBundle mainBundle] pathForResource:@"File A2" ofType:@"txt"];
       if (filePath) {
       NSString *text = [NSString stringWithContentsOfFile:filePath encoding:NSISOLatin1StringEncoding error:nil];
       if (text)
 {       self.textView= [[UITextView alloc] initWithFrame:CGRectMake(0,10,695,1100)];
         self.textView.text = text;
        [self.textView setFont:[UIFont systemFontOfSize:18]];
        [self.textView setBackgroundColor:[UIColor clearColor]];
        [self.textView setTextColor:[UIColor blackColor]];
         self.textView.editable = NO;
         self.textView.dataDetectorTypes = UIDataDetectorTypeNone;
        [self.scroll addSubview:self.textView];
   
   }
     }
   }
 }

 - (void)viewDidLoad
 {
         [super viewDidLoad];
   

   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

      self.slider.value = 0.387;
      self.label.text = @"0.39";
  }else{
      self.slider.value = 0.45;
      self.label.text = @"0.45";
    }
 }

 -(IBAction)makeSegmentedControl:(UISegmentedControl *)sender
 {
 if ([[UIDevice currentDevice ] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        UISegmentedControl __autoreleasing *segControl = [[UISegmentedControl alloc] initWithItems:
       [NSArray arrayWithObjects:@"Seg1",@"Seg2",@"Seg3",@"Seg4",@"Seg5",@"Seg6",nil]];
        CGRect segFrame = CGRectMake(22.20, self.view.frame.size.width / 2 + 225, self.view.frame.size.width - 40, 30);
       [segControl addTarget:self action:@selector(segPressed:) forControlEvents:UIControlEventValueChanged];
        segControl.frame = segFrame;
        segControl.tintColor = [UIColor blackColor];
       [[UISegmentedControl appearance] setTitleTextAttributes: @
 {
        NSForegroundColorAttributeName : [UIColor whiteColor]
 }
        forState:UIControlStateNormal];
        [self.view addSubview:segControl];
         sender.hidden = YES;
 }else{
        UISegmentedControl __autoreleasing *segControl = [[UISegmentedControl alloc] initWithItems:
       [NSArray arrayWithObjects:@"Seg1",@"Seg2",@"Seg3",@"Seg4",@"Seg5",@"Seg6",nil]];
        CGRect segFrame = CGRectMake(20.20, self.view.frame.size.width / 2 + 430, self.view.frame.size.width - 40, 25);
       [segControl addTarget:self action:@selector(segPressed:) forControlEvents:UIControlEventValueChanged];
        segControl.frame = segFrame;
        segControl.tintColor = [UIColor blackColor];
       [[UISegmentedControl appearance] setTitleTextAttributes: @
 {
         NSForegroundColorAttributeName : [UIColor whiteColor]
 }
          forState:UIControlStateNormal];
         [self.view addSubview:segControl];
          sender.hidden = YES;
      }
 } 

 #define screen_size_device (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON) 
 - (IBAction)makeSegmentedControl:(UISegmentedControl *)sender
 {
    if ([[UIDevice currentDevice ] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
    if (screen_size_device) {
        UISegmentedControl __autoreleasing *segControl = [[UISegmentedControl alloc] initWithItems:
       [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",nil]];
        CGRect segFrame = CGRectMake(22.20, self.view.frame.size.width / 2 + 227.5, self.view.frame.size.width - 40, 30);
       [segControl addTarget:self action:@selector(segPressed:) forControlEvents:UIControlEventValueChanged];
        segControl.frame = segFrame;
        segControl.tintColor = [UIColor yellowColor];
       [[UISegmentedControl appearance] setTitleTextAttributes: @
 {
       NSForegroundColorAttributeName : [UIColor whiteColor]
 }
       forState:UIControlStateNormal];
      [self.view addSubview:segControl];
       sender.hidden = YES;
 }else{
       UISegmentedControl __autoreleasing *segControl = [[UISegmentedControl alloc] initWithItems:
      [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",nil]];
       CGRect segFrame = CGRectMake(21.80, self.view.frame.size.width / 2 + 171.5, self.view.frame.size.width - 40, 25);
      [segControl addTarget:self action:@selector(segPressed:) forControlEvents:UIControlEventValueChanged];
       segControl.frame = segFrame;
       segControl.tintColor = [UIColor yellowColor];
      [[UISegmentedControl appearance] setTitleTextAttributes: @
 {
       NSForegroundColorAttributeName : [UIColor whiteColor]
 }
       forState:UIControlStateNormal];
      [self.view addSubview:segControl];
       sender.hidden = YES;
    }
 }else{
       UISegmentedControl __autoreleasing *segControl = [[UISegmentedControl alloc] initWithItems:
      [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",nil]];
       CGRect segFrame = CGRectMake(20.20, self.view.frame.size.width / 2 + 437, self.view.frame.size.width - 40, 25);
      [segControl addTarget:self action:@selector(segPressed:) forControlEvents:UIControlEventValueChanged];
       segControl.frame = segFrame;
       segControl.tintColor = [UIColor yellowColor];
      [[UISegmentedControl appearance] setTitleTextAttributes: @
 {
       NSForegroundColorAttributeName : [UIColor whiteColor]
 }
       forState:UIControlStateNormal];
      [self.view addSubview:segControl];
       sender.hidden = YES;
 }
      [_imageView20 stopAnimating];
       _imageView21.image = nil;
       UIAlertView __autoreleasing *alertView = [[UIAlertView alloc] initWithTitle:@"Please Select A Track Below 1-6"
       message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil ];
      [alertView show];
 }


 if ([[UIDevice currentDeviceuserInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       CGSize result = [[UIScreen mainScreenbounds].size;
       if (result.height == 480) {
            NSLog(@"iPhone 4");
       self.view = [[NSBundle mainBundleloadNibNamed:@"BrainWavesViewController_i4" owner:self options:nil][0];
     } if (result.height == 568) {
            NSLog(@"iPhone 5");
       self.view = [[NSBundle mainBundleloadNibNamed:@"BrainWavesViewController" owner:self options:nil][0];
     }
  }else{
            NSLog(@"iPad");
       self.view = [[NSBundle mainBundleloadNibNamed:@"BrainWavesViewController_iPad" owner:self options:nil][0];
  }


 #import "AppDelegate.h"
 @implementation AppDelegate
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
     if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
           CGSize iOSDeviceScreenSize = [[UIScreen mainScreenbounds].size;
           if (iOSDeviceScreenSize.height == 480) {
           UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone_i4" bundle:nil];
           UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
           self.window = [[UIWindow allocinitWithFrame:[[UIScreen mainScreenbounds]];
           self.window.rootViewController  = initialViewController;
          [self.window makeKeyAndVisible];
           NSLog(@"iPhone 4");
 }
          if (iOSDeviceScreenSize.height == 568) {
          UIStoryboard *iPhone5Storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
          UIViewController *initialViewController = [iPhone5Storyboard instantiateInitialViewController];
          self.window = [[UIWindow allocinitWithFrame:[[UIScreen mainScreenbounds]];
          self.window.rootViewController  = initialViewController;
         [self.window makeKeyAndVisible];
          NSLog(@"iPhone 5");
     }
  }else{
          UIStoryboard *iPadStoryboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
          UIViewController *initialViewController = [iPadStoryboard instantiateInitialViewController];
          self.window = [[UIWindow allocinitWithFrame:[[UIScreen mainScreenbounds]];
          self.window.rootViewController  = initialViewController;
         [self.window makeKeyAndVisible];
           NSLog(@"iPad");
 }
         AVAudioSession *audioSession = [AVAudioSession sharedInstance];
         NSError *categoryError = nil;
         BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback                
         withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&categoryError];
         if (!success) {
               NSLog(@"%@",  [categoryError localizedDescription]);
               exit(1);
 }
        NSError *activationError = nil;
        success = [audioSession setActive:YES error:&activationError];
        if (!success) {
              NSLog(@"%@",  [activationError localizedDescription]);
              exit(1);
 }
         [UIAlertView beginAnimations:nil context:nil];
         [UIAlertView setAnimationDuration:0.5];
         return YES;
 }
 - (void)applicationWillResignActive:(UIApplication *)application
 {
 }
 - (void)applicationDidEnterBackground:(UIApplication *)application
 {
 }
 - (void)applicationWillEnterForeground:(UIApplication *)application
 {
 }
 - (void)applicationDidBecomeActive:(UIApplication *)application
 {
 }
 - (void)applicationWillTerminate:(UIApplication *)application
 {
 }
 @end   

  #define screen_size_device (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)

  - (void) viewDidLoad  {
          [super viewDidLoad];
          if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)  {
    }else{
         _separatorView = [[UIView allocinitWithFrame:CGRectMake (0.020.0800.05.0)];
         _separatorView.backgroundColor = [UIColor blackColor];
        [self.view addSubview:_separatorView];
  } 
    NSError *error = nil;
    NSError *error2 = nil;
    //_scroll.delegate = self;
      _scroll.layer.cornerRadius = 15.0f;
     [_scroll setBackgroundColor:[UIColor blackColor]];
     [_scroll.layer setBorderColor:[[UIColor blackColorCGColor]];
      _scroll.layer.borderWidth = 2.5f;
      _button.layer.borderWidth = 2.0f;
      _button.layer.borderColor = [[UIColor greenColorCGColor];
     [_button.layer setCornerRadius5.0];
      _button.clipsToBounds = YES;
     [_button1.layer setCornerRadius1.8];
      _button1.clipsToBounds = YES;
     [_button2.layer setCornerRadius1.8];
      _button2.clipsToBounds = YES;
      self.view.backgroundColor = [UIColor greenColor];
      if ([[UIDevice currentDeviceuserInterfaceIdiom] == UIUserInterfaceIdiomPhone)  {
             NSString *filePath = [[NSBundle mainBundlepathForResource:@"Info" ofType:@"txt"];
           if (filePath)  {
                NSString *text = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
               if (text)  {
                    if (screen_size_device)  {
                          _textView= [[UITextView allocinitWithFrame:CGRectMake (20.521.0278.5481.5)];
                          _textView.text = text;
                         [_textView setFont:[UIFont systemFontOfSize:10]];
                         [_textView setBackgroundColor:[UIColor clearColor]];
                         [_textView setTextColor:[UIColor whiteColor]];
                          _textView.layer.cornerRadius = 15.0f;
                          _textView.editable = NO;
                          _scroll.contentSize = CGSizeMake (278.5481.5);
                         [_scroll addSubview_textView];
                         [self.view addSubview_textView];
                   }else{
                          _textView= [[UITextView allocinitWithFrame:CGRectMake (20.521.0278.5393.5)];
                          _textView.text = text;
                         [_textView setFont:[UIFont systemFontOfSize:10]];
                         [_textView setBackgroundColor:[UIColor clearColor]];
                         [_textView setTextColor:[UIColor whiteColor]];
                          _textView.layer.cornerRadius = 15.0f;
                          _textView.editable = NO;
                          _scroll.contentSize = CGSizeMake (278.5393.5);
                         [_scroll addSubview_textView];
                         [self.view addSubview_textView];
                  }
      }
      if (error != nil)  {
           NSLog(@"%@", [error localizedDescription]);
           exit(1);
   }
          }
     }else{
        NSString *filePath = [[NSBundle mainBundlepathForResource:@"Info" ofType:@"txt"];
        if (filePath)  {
             NSString *text = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error2];
             if (text)
      {   
            
_textView= [[UITextView allocinitWithFrame:CGRectMake (38.042.5692.5916.0)];
            _textView.text = text;
           [_textView setFont:[UIFont systemFontOfSize:11]];
           [_textView setBackgroundColor:[UIColor clearColor]];
           [_textView setTextColor:[UIColor whiteColor]];
            _textView.layer.cornerRadius = 15.0f;
            _textView.editable = NO;
            _scroll.contentSize = CGSizeMake (692.5916.0);
           [_scroll addSubview:_textView];
           [self.view addSubview_textView];
       }
             if (error2 != nil)  {
                  NSLog(@"%@", [error2 localizedDescription]);
                  exit(1);
               }
          }
      }
 }


 

 UI Controls Samples  
 h

 #import <UIKit/UIKit.h>
 @interface ViewController : UIViewController
 @property (nonatomic, assign) NSInteger count;
 @property (nonatomic, weak) IBOutlet UILabel *countLabel;
 @property (nonatomic, weak) IBOutlet UILabel *countLabel1;
 @property (nonatomic, weak) IBOutlet UILabel *countLabel2;
 @property (nonatomic, strong) IBOutlet UISlider *slider;
 @property (nonatomic, strong) IBOutlet UISlider *slider1;
 @property (nonatomic, strong) IBOutlet UIButton *button;
 @property (nonatomic, strong) IBOutlet UIButton *button1;
 @property (nonatomic, strong) IBOutlet UIButton *button2;
 @property (nonatomic, strong) IBOutlet UIButton *button3;
 @property (nonatomic, strong) IBOutlet UISlider *countSlider;
 @property (strong, nonatomic) IBOutlet UITextField *textField;
 @property (strong, nonatomic) IBOutlet UITextField *textField1;
 @property (strong, nonatomic) IBOutlet UIStepper *stepper;
 @property (strong, nonatomic) IBOutlet UISegmentedControl *segmentedControl;
 @property (strong, nonatomic) IBOutlet UIButton *segButton;
 @property (strong, nonatomic) IBOutlet UIView *view1;
 @property (strong, nonatomic) IBOutlet UIImageView *imageView;
 - (IBAction)colorButtonPressed:(UIButton *)sender;
 - (IBAction)resetButtonPressed:(UIButton *)sender;
 - (IBAction)value:(UISlider *)sender;
 - (IBAction)switchOnOff:(UISwitch *)sender;
 - (IBAction)centre:(UIButton *)sender;
 - (IBAction)sliderAction:(UISlider *)sender;
 - (IBAction)minMax:(UIButton *)sender;
 - (IBAction)textFieldAction:(UITextField *)sender;
 - (IBAction)stepperControl:(UIStepper *)sender;
 - (IBAction)seg:(UISegmentedControl *)sender;
 - (IBAction)programmaticSegmentedControl:(UISegmentedControl *)sender;
 @end
 m
 #import "ViewController.h"
 @interface ViewController ()
 @end
 @implementation ViewController
 @synthesize count = _count;
 @synthesize countLabel = _countLabel, countLabel1 = _countLabel1, countLabel2 = _countLabel2;
 @synthesize button = _button, button1 = _button1, button2 = _button2, button3 = _button3;
 @synthesize segmentedControl = _segmentedControl;
 @synthesize slider = _slider, slider1 = _slider1;
 @synthesize countSlider = _countSlider;
 @synthesize textField1 = _textField1;
 @synthesize textField = _textField;
 @synthesize stepper = _stepper;
 @synthesize segButton = _segButton;
 @synthesize imageView = _imageView;
 @synthesize view1 = _view1;
 - (void)didReceiveMemoryWarning
 { 
      [super didReceiveMemoryWarning];
 }
 - (void)viewDidLoad
 {
      [super viewDidLoad];
       self.view.backgroundColor = [UIColor orangeColor];
       self.view1.backgroundColor = [UIColor blackColor];
       self.count = 0.0;
       self.slider.value = 0.0;
       self.slider1.value = 0.0;
       self.imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"100.png"],
                                                                  [UIImage imageNamed:@"101.png"],
                                                                  [UIImage imageNamed:@"102.png"],
                                                                  [UIImage imageNamed:@"103.png"],
                                                                  [UIImage imageNamed:@"104.png"],  nil];
       self.imageView.animationDuration = 3.0;
       self.imageView.animationRepeatCount = -1;
      [self.imageView startAnimating];
 }
 - (IBAction)value:(UISlider *)sender{
       float currentValue;
       currentValue = [self.slider value];
       NSString *string = [[NSString alloc] initWithFormat:@" %.0f", currentValue ];
       self.countLabel1.text = string;
 }
 - (IBAction)colorButtonPressed:(UIButton *)sender
 {
    if ([sender.titleLabel.text isEqualToString:@"Yellow"]) {
         self.view.backgroundColor = [UIColor yellowColor];
        [sender setTitle:@"Orange" forState:UIControlStateNormal];
        [sender setTintColor:[UIColor orangeColor]];
         self.count = self.count + 10;
         self.countLabel.text = [NSString stringWithFormat:@"%d", self.count];
         self.countSlider.value = self.count;
 } else {
         self.view.backgroundColor = [UIColor orangeColor];
        [sender setTitle:@"Yellow" forState:UIControlStateNormal];
        [sender setTintColor:self.view.tintColor];
      //[sender setTintColor:[UIColor yellowColor]];
         self.count = self.count - 5 ;
         self.countLabel.text = [NSString stringWithFormat:@"%d", self.count];
         self.countLabel2.text = [NSString stringWithFormat:@"-%d", self.count];
         self.countSlider.value = self.count;
     }
 }
 - (IBAction)resetButtonPressed:(UIButton *)sender
 {
         self.count = 0;
         self.countSlider.value = self.count;
         self.slider1.value = self.count;
        [self sliderAction:self.slider1];
         self.countLabel.text = [NSString stringWithFormat:@"%d", self.count];
         self.countLabel1.text = [NSString stringWithFormat:@"%d", self.count];
         self.countLabel2.text = [NSString stringWithFormat:@"%d", self.count];
         self.textField.text = @"";
         self.textField1.text = @"";
 }
 - (IBAction)switchOnOff:(UISwitch *)sender{
    if (sender.on) {
        self.slider.enabled = YES;
        self.button.enabled = YES;
      self.button1.enabled = YES;
  self.button2.enabled = YES;
  self.button3.enabled = YES;
  self.slider1.enabled =YES;
  self.stepper.enabled =YES;
  self.segButton.enabled =YES;
  self.textField.enabled =YES;
  self.textField1.enabled =YES;
  self.segmentedControl.enabled =YES;
 }else{
  self.slider.enabled = NO;
  self.button.enabled = NO;
  self.button1.enabled = NO;
  self.button2.enabled = NO;
  self.button3.enabled = NO;
  self.slider1.enabled =NO;
  self.stepper.enabled =NO;
  self.segButton.enabled =NO;
  self.textField.enabled =NO;
  self.textField1.enabled =NO;
self.segmentedControl.enabled =NO;
     }
 } 
 - (IBAction)centre:(UIButton *)sender{
        self.slider.value = 50;
        self.slider1.value = .5;
        self.countLabel1.text = [NSString stringWithFormat:@"%.2f", self.slider.value];
       [self sliderAction:self.slider1];
 }
 - (IBAction)sliderAction:(UISlider *)sender{
        self.view.backgroundColor =[UIColor colorWithRed:sender.value
                                                   green:sender.value
                                                    blue:sender.value
                                                   alpha:1 ];
        self.textField.text = @"Gray Scale Control";
        self.textField1.text = @"Gray Scale Control";
 }
 - (IBAction)minMax:(UIButton *)sender{
    if ([sender.titleLabel.text isEqualToString:@"set max"]) {
        [sender setTitle:@"set min" forState:UIControlStateNormal];
         self.slider1.value = 1;
 } else {
        [sender setTitle:@"set max" forState:UIControlStateNormal];
         self.slider1.value = 0;
    }
     [self sliderAction:self.slider1];
 }
 - (IBAction)textFieldAction:(UITextField *)sender
 {
       [self.textField resignFirstResponder];
       [self.textField1 resignFirstResponder];
        self.textField1.text = [NSString stringWithFormat:@"%@", self.textField.text]; 
    if (self.textField.text.length > 0) {
        self.countLabel.text = @"Text Field Input Reflected";
    }
 }
 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
       [self.textField resignFirstResponder];
       [self.textField1 resignFirstResponder];
        self.textField.text = [NSString stringWithFormat:@"%@%@", self.textField.text, self.textField1.text];
        self.countLabel.text = @"Text Fields Combined";
       [super touchesBegan:touches withEvent:event];
 }
 - (IBAction)stepperControl:(UIStepper *)sender {
        NSLog(@"stepper value is %.4f", sender.value);
        self.view.backgroundColor = [UIColor colorWithRed:0.5
                                                    green:0.5
                                                     blue:sender.value                
                                                    alpha:1.0 ];
        self.textField.text = [NSString stringWithFormat:@"Stepper Value %.2f", sender.value];
        self.textField1.text@"Range = 0 - 1";
 }
 - (IBAction)seg:(UISegmentedControl *)sender
 {
        NSLog(@"%d", sender.selectedSegmentIndex);
        switch (sender.selectedSegmentIndex) {
        case 0:
            self.textField.text = @" 1st segment pressed ";
            self.view.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
            break;
        case 1:
            self.textField.text = @" 2nd segment pressed ";
            self.view.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.5 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithRed:1.0 green:0.5 blue:0.0 alpha:1.0];
            break;
        case 2:
            self.textField.text = @" 3rd segment pressed ";
            self.view.backgroundColor = [UIColor colorWithRed:0.5 green:1.0 blue:0.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.5 alpha:1.0];
            break;
        case 3:
            self.textField.text = @" 4th segment pressed ";
            self.view.backgroundColor = [UIColor colorWithRed:0.5 green:1.0 blue:0.5 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.8 alpha:1.0];
            break;
        case 4:
            self.textField.text = @" 5th segment pressed ";
            self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.7 blue:0.5 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:1.0];
            break;
        case 5:
            self.textField.text = @" 6th segment pressed ";
            self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
            break;
        default:
            break;
      }
       self.textField1.text = @"Seg Control";
 }
 - (IBAction)segPressed:(UISegmentedControl *)sender
 {
        NSLog(@"%d", sender.selectedSegmentIndex);
        switch (sender.selectedSegmentIndex) {
        case 0:
            self.textField.text = @" Seg 1st segment pressed ";
            self.view.backgroundColor = [UIColor colorWithHue:1.0 saturation:1.0 brightness:1.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithHue:0.1 saturation:0.1 brightness:0.9 alpha:1.0];
            break;
        case 1:
            self.textField.text = @" Seg 2nd segment pressed ";
            self.view.backgroundColor = [UIColor colorWithHue:0.9 saturation:0.9 brightness:1.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithHue:0.4 saturation:0.4 brightness:0.4 alpha:1.0];
            break;
        case 2:
            self.textField.text = @" Seg 3rd segment pressed ";
            self.view.backgroundColor = [UIColor colorWithHue:0.8 saturation:0.8 brightness:1.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1.0];
            break;
        case 3:
            self.textField.text = @" Seg 4th segment pressed ";
            self.view.backgroundColor = [UIColor colorWithHue:1.0 saturation:0.7 brightness:1.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithHue:0.8 saturation:0.8 brightness:0.8 alpha:1.0];
            break;
        case 4:
            self.textField.text = @" Seg 5th segment pressed ";
            self.view.backgroundColor = [UIColor colorWithHue:1.0 saturation:0.6 brightness:1.0 alpha:1.0];
            self.view1.backgroundColor = [UIColor colorWithHue:1.0 saturation:1.0 brightness:1.0 alpha:1.0];
            break;
        default:
            break;
      }
       self.textField1.text = @"Programmatic Seg Control";
 }
 - (IBAction)programmaticSegmentedControl:(UISegmentedControl *)sender
 {
      UISegmentedControl __autoreleasing *segControl = [[UISegmentedControl alloc] initWithItems:
      [NSArray arrayWithObjects:@"S1",@"S2",@"S3",@"S4",@"S5",nil]];
      CGRect segFrame = CGRectMake(20.0, self.view.frame.size.width / 2 + 307.5, self.view.frame.size.width - 40.0, 30.0);
      [segControl addTarget:self action:@selector(segPressed :) forControlEvents:UIControlEventValueChanged];
      segControl.frame = segFrame;
      segControl.tintColor = [UIColor yellowColor];
      [[UISegmentedControl appearance] setTitleTextAttributes: @
 {
      NSForegroundColorAttributeName : [UIColor blueColor]
 }
      forState:UIControlStateNormal];
     [self.view addSubview:segControl];
      sender.hidden = YES;
      self.textField.text = @"Seg Opened";
      self.textField1.text = @"Seg Opened";
 }
 @end


  UI Controls CGRect  

 #import <UIKit/UIKit.h>
 #import <QuartzCore/QuartzCore.h>
 @interface ViewController : UIViewController
 <UIAlertViewDelegate, UIActionSheetDelegate>
 @property (strong, nonatomic) UILabel *label;
 @property (strong, nonatomic) UISlider *slider;
 @property (strong, nonatomic) UIStepper *stepper;
 @property (strong, nonatomic) UISegmentedControl *segControl;
 @property (strong, nonatomic) UISwitch *uiSwitch;
 @property (strong, nonatomic) UIActivityIndicatorView *activityView;
 @property (strong, nonatomic) UITextField *textField;
 @property (strong, nonatomic) UITextView *textView;
 @end

 #import "ViewController.h"
 @interface ViewController ()
 {
       int currentAction;
       UIView *subView1;
       UIView *subView2;
 }
 @end
 @implementation ViewController
 - (void)viewDidLoad {
          [super viewDidLoad];
          CGRect frame = CGRectMake (5.0, 630.0, 365.0, 25.0);
          UIButton *button = [[UIButton alloc] initWithFrame:frame]; button.backgroundColor = [UIColor redColor];
          button.layer.borderWidth = 2.0fbutton.layer.borderColor = [[UIColor blackColor] CGColor];
          [button.layer setCornerRadius: 5.0]; button.clipsToBounds = YES;
          [button setTitle:@"Press Button" forState:UIControlStateNormal];
          [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
          [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
          [button addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
          [button addTarget:self action:@selector(buttonDown:) forControlEvents:UIControlEventTouchDown];
          [button addTarget:self action:@selector(slidOutsideButton:) forControlEvents:UIControlEventTouchUpOutside];
          [self.view addSubview:button]; NSLog(@"Button %@", button);
          [_textField resignFirstResponder];
 }
 - (IBAction)buttonAction:(UIButton *)sender
 {
       if (currentAction == 0) {
           currentAction = 1;
           CGRect frame = CGRectMake (5.0, 20.0, 365.0, 580.0);
           subView1 = [[UIView alloc] initWithFrame:frame]; subView1.backgroundColor = [UIColor redColor];
           [self.view addSubview:subView1]; NSLog(@"subView 1 %@", subView1);
           _label.text = @"";
 }else if (currentAction == 1) {
           currentAction = 2;
           CGRect frame = CGRectMake (10.0, 25.0, 355.0, 570.0);
           subView2= [[UIView alloc] initWithFrame:frame]; subView2.backgroundColor = [UIColor blueColor];
           [self.view addSubview:subView2]; NSLog(@"subView 2 %@", subView2);
 }else if (currentAction == 2) {
           currentAction = 3;
           CGRect frame = CGRectMake (5.0, 602.0, 365.0, 26.0);
           _label = [[UILabel alloc] initWithFrame:frame]; _label.backgroundColor = [UIColor blackColor];
           _label.text = @"UILabel"_label.textColor = [UIColor whiteColor]; _label.textAlignment = NSTextAlignmentCenter;
           [_label.layer setCornerRadius: 5.0]; _label.clipsToBounds = YES;
           [self.view addSubview:_label]; NSLog(@"Label %@", _label);
 }else if (currentAction == 3) {
           currentAction = 4;
           CGRect frame = CGRectMake (10.0, 50.0, 355.0, 26.0);
           _slider = [[UISlider alloc] initWithFrame:frame]; [_slider setBackgroundColor:[UIColor clearColor]];
           [_slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
           _slider.minimumValue = 0.0_slider.maximumValue = 1.0; _slider.value = 0.5; _slider.continuous = YES;
           [self.view addSubview:_slider]; NSLog(@"Slider %@", _slider);
           _label.text = @"Control UISlider";
 }else if (currentAction == 4) {
           currentAction = 5;
           CGRect frame = CGRectMake (165.0, 100.0, 50.0, 26.0);
           _uiSwitch = [[UISwitch alloc] initWithFrame:frame];
           [_uiSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
           [self.view addSubview:_uiSwitch]; NSLog(@"UISwitch %@", _uiSwitch);
           _label.text = @"Control UISwitch";
 }else if (currentAction == 5) {
           currentAction = 6;
           CGRect frame = CGRectMake (143.0, 200.0, 50.0, 26.0);
           _stepper = [[UIStepper alloc] initWithFrame:frame]; _stepper.tintColor = [UIColor redColor];
           [_stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
           _stepper.minimumValue = 0.0_stepper.maximumValue = 1.0_stepper.stepValue = 0.1;
           [self.view addSubview:_stepper]; NSLog(@"Stepper %@", _stepper);
           _label.text = @"Control UIStepper";
 }else if (currentAction == 6) {
           currentAction = 7;
           _segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"S1",@"S2",@"S3",@"S4",@"S5",nil]];
           CGRect segFrame = CGRectMake(20.0, self.view.frame.size.width / 2 + 100.5, self.view.frame.size.width - 40.0, 30.0);
           [_segControl addTarget:self action:@selector(segAction :) forControlEvents:UIControlEventValueChanged];
           _segControl.frame = segFrame; _segControl.tintColor = [UIColor yellowColor];
           [[UISegmentedControl appearance] setTitleTextAttributes: @
 {
           NSForegroundColorAttributeName : [UIColor redColor]
 }
           forState:UIControlStateNormal];
           [self.view addSubview:_segControl]; NSLog(@"Seg Control%@", _segControl);
           _label.text = @"Control UISegmentedControl";
 }else if (currentAction == 7) {
           currentAction = 8;
           CGRect frame = CGRectMake (25.0, 350.0, 326.0, 26.0);
           _textField = [[UITextField alloc] initWithFrame:frame]; _textField.backgroundColor = [UIColor whiteColor];
           _textField.text = @"UITextField"_textField.textAlignment = NSTextAlignmentCenter;
           _textField.layer.borderWidth = 2.0f_textField.layer.borderColor = [[UIColor blackColor] CGColor];
           [self.view addSubview:_textField]; NSLog(@"Text Field %@", _textField);
           _label.text = _textField.text;
 }else if (currentAction == 8) {
           currentAction = 9;
           CGRect frame = CGRectMake (25.0, 400.0, 326.0, 26.0);
           _textView = [[UITextView alloc] initWithFrame:frame];
           _textView.backgroundColor = [UIColor colorWithRed:255/255 green:255/255 blue:255/255 alpha:255/255];
           _textView.textColor = [UIColor colorWithRed:0/255 green:0/255 blue:0/255 alpha:255/255];
           _textView.textAlignment = NSTextAlignmentCenter[_textView setFont:[UIFont boldSystemFontOfSize:15]];
           _textView.layer.borderWidth = 2.0f_textView.layer.borderColor = [[UIColor blackColor] CGColor];
           _textView.text = @"UITextView"; _label.text = _textView.text;
           [self.view addSubview:_textView]; NSLog(@"Text View %@", _textView);
 }else if (currentAction == 9) {
           currentAction = 10;
           [_textField removeFromSuperview]; [_textView removeFromSuperview];
           _label.text = @"Removed UITextField And UITextView";
 }else if (currentAction == 10) {
           currentAction = 11;
           [_segControl removeFromSuperview];
           _label.text = @"Removed UISegmentedControl";
 }else if (currentAction == 11) {
           currentAction = 12;
           [_stepper removeFromSuperview];
           _label.text = @"Removed UIStepper";
 }else if (currentAction == 12) {
           currentAction = 13;
           [_uiSwitch removeFromSuperview];
           _label.text = @"Removed UISwitch";
 if ([_activityView isAnimating]) {
     [_activityView removeFromSuperview];
 }
 }else if (currentAction == 13) {
           currentAction = 14;
           [_slider removeFromSuperview];
           _label.text = @"Removed UISlider";
 }else if (currentAction == 14) {
           currentAction = 15;
           [subView1 removeFromSuperview];
           _label.text = @"Removed SubView 1";
 }else if (currentAction == 15) {
           currentAction = 16;
           [subView2 removeFromSuperview];
           _label.text = @"Removed SubView 2";
 }else if (currentAction == 16) {
           currentAction = 17;
           NSString *string = @"Goodbye !";
           UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"UI Fun" message:string delegate:self
                                                     cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
           [alertView show];
           NSLog(@"Text View %@", alertView);
           _label.text = @"UIAlertView";
 }
 if (currentAction == 17) {
     currentAction = 0;
   }
 }
 - (IBAction)sliderAction:(UISlider *)sender
 {
           UISlider *slider = (UISlider *)sender;
           float value = slider.value;
           _label.text = [NSString stringWithFormat:@"%.4f", slider.value];
           NSLog(@"%.4f", value);
           self.view.backgroundColor = [UIColor colorWithRed:sender.value
                                                       green:sender.value
                                                        blue:sender.value
                                                       alpha:1 ];
 }
 - (IBAction)switchAction:(UISwitch *)sender
 {
     if (sender.on) {
         [subView1 setBackgroundColor:[UIColor blueColor]];
         NSLog(@"subView 1 = Blue");
         CGRect frame = CGRectMake (165.0, 150.0, 50.0, 26.0);
         _activityView = [[UIActivityIndicatorView alloc] initWithFrame:frame];
         _activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
         [self.view addSubview:_activityView];
         [_activityView startAnimating];
         _label.text = @"Switch ON";
         NSLog(@"UIActivityIndicatorView Animating = Switch ON");
  }else{
         [subView1 setBackgroundColor:[UIColor redColor]];
         NSLog(@"subView 1 = Red");
         [_activityView stopAnimating];
         _label.text = @"Switch OFF";
         NSLog(@"UIActivityIndicatorView Terminated = Switch OFF");
     }
 }
 - (IBAction)stepperAction:(UIStepper *)sender
 {
         NSLog(@"Stepper Value is %.2f", sender.value);
         _label.text = [NSString stringWithFormat:@"UIStepper Value Is %.2f ", sender.value];
         subView2.backgroundColor = [UIColor colorWithRed:sender.value
                                                    green:sender.value
                                                     blue:sender.value
                                                    alpha:1 ];
 }
 - (IBAction)segAction:(UISegmentedControl *)sender
 {
         NSLog(@"%ld", (long)sender.selectedSegmentIndex);
         switch (sender.selectedSegmentIndex) {
              case 0:
                  self.view.backgroundColor = [UIColor colorWithHue:0.0 saturation:0.0 brightness:0.0 alpha:1.0];
                  subView1.backgroundColor = [UIColor colorWithHue:0.0 saturation:0.0 brightness:0.0 alpha:1.0];
                  subView2.backgroundColor = [UIColor colorWithHue:0.0 saturation:0.0 brightness:0.0 alpha:1.0];
                  _label.text = @"Segment 1 Pressed";
                  break;
              case 1:
                  self.view.backgroundColor = [UIColor colorWithHue:0.5 saturation:0.5 brightness:0.5 alpha:1.0];
                  subView1.backgroundColor = [UIColor colorWithHue:0.5 saturation:0.5 brightness:0.5 alpha:1.0];
                  subView2.backgroundColor = [UIColor colorWithHue:0.5 saturation:0.5 brightness:0.5 alpha:1.0];
                  _label.text = @"Segment 2 Pressed";
                  break;
              case 2:
                  self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
                  subView1.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
                  subView2.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
                  _label.text = @"Segment 3 Pressed";
                  break;
              case 3:
                  self.view.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
                  subView1.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
                  subView2.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
                  _label.text = @"Segment 4 Pressed";
                  break;
              case 4:
                  self.view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5];
                  subView1.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5];
                  subView2.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5];
                  _label.text = @"Segment 5 Pressed";
                  break;
             default:
                  break;
        }
 }
 - (void)buttonTouched:(UIButton *)sender
 {
         NSLog(@"Button Touched Up Inside");
 }
 - (void)buttonDown:(UIButton *)sender
 {
         NSLog(@"Button Down");
 }
 - (void)slidOutsideButton:(UIButton *)sender
 {
         NSLog(@"Slid Outside Button");
 }
 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
         switch (buttonIndex) {
             case 0: {
                 NSLog(@"UIAlertView Button Touched");
                 UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Goodbye Again" delegate:self
                 cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:nil];
                 actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
                 [actionSheet showInView:self.view]; NSLog(@"Text View %@", actionSheet);
                 _label.text = @"";
  }
                 break;
             default:
                 break;
    }   
 }
 - (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
 {
           switch (buttonIndex) {
               case 0: {
                   NSLog(@"UIActionSheet Canceled");
                   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"UIActionSheet" message:@"DISMISSED"                                    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                   [alertView show]; NSLog(@"Text View %@", alertView);
  }
                   break;
               default:
                   break;
         }
 }
 - (void)didReceiveMemoryWarning {
         [super didReceiveMemoryWarning];
 }
 @end



   Loops Examples In IOS (Objective C)   
 h

 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController

 @property (strong, nonatomic) IBOutlet UILabel *label;

 - (IBAction)action:(id)sender;

 @end

 m

 #import "ViewController.h"

 @interface ViewController ()

 @end

 @implementation ViewController

 @synthesize label;

 - (void)viewDidLoad

 {

    [super viewDidLoad];

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];  

 }

 - (IBAction)action:(id)sender {

int  i = 0;

do {
             i++;

NSLog(@"number1 %d", i);

if (i == 3) {

NSLog(@" section 3  %d", i);

}

if (i == 6) {

NSLog(@"section 6  %d", i);

self.label.text = @"result is 6";

self.view.backgroundColor = [UIColor yellowColor];

NSLog(@"background color changed ");

}

if (i == 9) {

NSLog(@"section 9  %d", i);

}

if (i < 5) {

NSLog(@"value is less than 5   %d", i);

}

} while (i < 10);

        int y =0;

BOOL terminateLoop;

terminateLoop = false;

while (!terminateLoop) {

y++;

NSLog(@"number1 %d", y);

y = y + 1;

NSLog(@"number2 %d", y);

y += 1;

NSLog(@" number3 %d", y);

if (y > 50) {

terminateLoop = true;

NSLog(@"reached 51  %d", y);

}

}

NSInteger index;

NSInteger number = 1;

float sum;

for (index = 0; index < 10; index++) {

NSLog(@" index  %d", index);

sum = number + index * 3.14159;

NSLog(@" sum  %f", sum);

if (sum == 10) {

NSLog(@" index 10  %f", sum);

}else{

NSLog(@" error ");

}

}

        NSInteger numbers [100];

for (int i = 0; i < 20; i++)
        numbers[i] = i * 3;
        NSLog(@" loop result is %d : %d",i,  numbers[i]);
}

NSMutableArray *numbers1 = [NSMutableArray array];
        [numbers1 addObject:@" Inserted Object "];
        for (int i = 1; i <= 30; i++) {
        [numbers1 addObject:[NSNumber numberWithInteger:i]];
        NSLog(@" loop 2 result is  %@", [numbers1 objectAtIndex:i]);
    }
        int students,testScores [8] = {88,67,92,55,75,98,54,89};

float averageResult = 0;
        for (students = 0, averageResult = 0; students < 8; students++) {
        averageResult += testScores[students];
  }     

        NSLog(@"average result is %.1f", averageResult/8);

        int tests, studentsPresent, scores[5][5] = {{60,72,31,90,95},{77,48,66,82,36},{99,89,77,54,52},
                                                   {70,70,81,90,54},{68,62,45,90,98}};
        float averageResult1;
        for (tests = 0; tests < 5; tests++) {
            for (studentsPresent = 0, averageResult1 = 0; studentsPresent < 5; studentsPresent++) {
            averageResult1 += scores[tests][studentsPresent];
       }      
            NSLog(@"average for test %i is %.1f", tests + 1, averageResult1 / 5);
     }

 }

 @end

  UITableView(RootViewController)    __autoreleasing (Switch Case) Color Info     

 

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
      int hexRGB = 0// use with hexRGB
      DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController"  
      bundle:nil];
      UIColor __autoreleasing *viewColor;
      switch (indexPath.row) {
          case 0:
              viewColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];                 //black (1/1/1 Control)
              break;
          case 1:
              viewColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];                 //white
              break;
          case 2:
              viewColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];                 //red
              break;
          case 3:
              viewColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:1];                 //green
              break;
          case 4:
              viewColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:1];                 //blue
              break;
          case 5:
              viewColor = [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1];              //manipulated gray
              break;
          case 6:
              viewColor = [UIColor colorWithRed:.3 green:.6 blue:.1 alpha:1];              //manipulated green
              break;
          case 7:
              viewColor = [UIColor colorWithRed:.3 green:.6 blue:.1 alpha:.6];             //green Alpha Control
              break;
          case 8:
              viewColor = [UIColor colorWithRed:.3 green:.6 blue:.1 alpha:.3];             //green Alpha Control
              break;
          case 9:
              viewColor = [UIColor colorWithRed:.3 green:.6 blue:.1 alpha:.1];             //green Alpha Control
              break;
          case 10:
              viewColor = [UIColor colorWithRed:.3 green:.6 blue:.1 alpha:.0];             //green Alpha Control
              break;
          case 11:
              viewColor = [UIColor colorWithHue:1 saturation:1 brightness:1 alpha:1];      //hue,saturation,brightness(full)
              break;
          case 12:
              viewColor = [UIColor colorWithHue:.5 saturation:1 brightness:1 alpha:1];     //hue,saturation,brightness(.5h)
              break;
          case 13:
              viewColor = [UIColor colorWithHue:1 saturation:.5 brightness:1 alpha:1];     //hue,saturation,brightness(.5s)
              break;
          case 14:
              viewColor = [UIColor colorWithHue:1 saturation:1 brightness:.5 alpha:1];     //hue,saturation,brightness(.5b)
              break;
          case 15:
              viewColor = [UIColor colorWithRed:(hexRGB & 0xFF0000) green:(hexRGB & 0x00FF00) blue:(hexRGB & 0x0000FF)                     alpha:1];                                                                    //hexRGB (black)
              break;
          case 16:
              viewColor = [UIColor colorWithWhite:1.0 alpha:1.0];                          //white
              break;
          case 17:                          //These work but they are not meant to work in this situation, USE (0 - 1 Ratio)
              viewColor = [UIColor colorWithRed:255/255 green:255/255 blue:255/255 alpha:1.0];        //white
              break;
          case 18:
              viewColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:1];                      //white
              break;     
          case 19:
              viewColor = [UIColor colorWithRed:0/255 green:0/255 blue:0/255 alpha:1.0];              //black
              break;
          case 20:
              viewColor = [UIColor colorWithRed:0/255 green:0/255 blue:255/255 alpha:1.0];            //blue
              break;
          case 21:
              viewColor = [UIColor colorWithRed:0/255 green:255/255 blue:0/255 alpha:1.0];            //green
              break;
          case 22:
              viewColor = [UIColor colorWithRed:255/255 green:0/255 blue:0/255 alpha:1.0];            //red
              break;
          case 23:
              viewColor = [UIColor colorWithRed:255/255 green:0/255 blue:255/255 alpha:1.0];          //pink
           break;           case 24:
              viewColor = [UIColor colorWithRed:128 green:0 blue:128 alpha:1];                        //pink
              break;
          case 25:
              viewColor = [UIColor colorWithRed:0/255 green:255/255 blue:255/255 alpha:1.0];          //cyan
              break;   
          case 26:
              viewColor = [UIColor colorWithRed:0 green:128 blue:128 alpha:1];                        //cyan
              break;
          case 27:
              viewColor = [UIColor colorWithRed:255/255 green:255/255 blue:0/255 alpha:1.0];          //yellow
              break;
          case 28:
              viewColor = [UIColor colorWithRed:0 green:0 blue:128 alpha:1];                          //navy
              break;
          default:
              break;
    }
    detailViewController.view.backgroundColor = viewColor;
    [self.navigationController pushViewController:detailViewController animated:YES];
 }
 @end

  App Delegate Samples in IOS  

 h

 #import <UIKit/UIKit.h>

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (weak, nonatomic) IBOutlet UILabel *label;

 @property (strong, nonatomic) IBOutlet UIWindow *window;

 - (IBAction)action:(id)sender;

 @end

 m

 #import "AppDelegate.h"

 @implementation AppDelegate

 @synthesize label;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 {

     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

     self.window.backgroundColor = [UIColor whiteColor];

     [self.window makeKeyAndVisible];

     return YES;

 }

 - (void)applicationWillResignActive:(UIApplication *)application

 {

 }

 - (void)applicationDidEnterBackground:(UIApplication *)application

 {  

 }

 - (void)applicationWillEnterForeground:(UIApplication *)application

 {

 }

 - (void)applicationDidBecomeActive:(UIApplication *)application

 {

 }

 - (void)applicationWillTerminate:(UIApplication *)application

 {

 }

 - (IBAction)action:(id)sender {

self.label.text = @"hello";

self.label.backgroundColor = [UIColor redColor];

self.label.textColor = [UIColor blueColor];

 }

 @end

 h

 #import <UIKit/UIKit.h>

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) UIWindow *window;

 @end

 m

 #import "AppDelegate.h"

 @implementation AppDelegate

 - (void)dealloc

 {

    [_window release];

    [super dealloc];

 }

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 {

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

        int a;

a = 10;

int b = 20;

float sum;

sum = a + b;

NSLog(@"sum is %.0f", sum);

//NSString *string = @" hello ";

NSString *message  = [NSString stringWithFormat:@" %.0f", sum];  

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"hello" message:message

    delegate:self

   cancelButtonTitle:@"OK"

   otherButtonTitles:@"Ok Thank You",

                  @"No Thank You", nil];

NSLog(@"alert %@ ", alertView);

[alertView show];

        self.window.backgroundColor = [UIColor whiteColor];

       [self.window makeKeyAndVisible];

       return YES;

       [alertView release];

       [message release];

 }

 - (void)applicationWillResignActive:(UIApplication *)application

 {

 - (void)applicationDidEnterBackground:(UIApplication *)application

 {  

 }

 - (void)applicationWillEnterForeground:(UIApplication *)application

 {

 }

 - (void)applicationDidBecomeActive:(UIApplication *)application

 {

 }

 - (void)applicationWillTerminate:(UIApplication *)application

 {

 }

 @end

 h

 #import <UIKit/UIKit.h>

 @class ViewController;

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) UIWindow *window;

 @property (strong, nonatomic) ViewController *viewController;

 @end

 m

 #import "AppDelegate.h"

 #import "ViewController.h"

 @implementation AppDelegate

 @synthesize window = _window;
 @synthesize viewController = _viewController;

 - (void)dealloc

 {

     [_window release];   

     [_ViewController release];

     [super dealloc];

 }

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 {

       self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

       self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]autorelease];

       self.window.rootViewController = self.viewController;

       self.window.backgroundColor = [UIColor whiteColor];

      [self.window makeKeyAndVisible];

       return YES;

 }

 - (void)applicationWillResignActive:(UIApplication *)application

 {

 }

 - (void)applicationDidEnterBackground:(UIApplication *)application

 {  

 }

 - (void)applicationWillEnterForeground:(UIApplication *)application

 {

 }

 - (void)applicationDidBecomeActive:(UIApplication *)application

 {

 }

 - (void)applicationWillTerminate:(UIApplication *)application

 {

 }

 @end

 h

 #import <UIKit/UIKit.h>

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) UIWindow *window;

 @property (strong, nonatomic) IBOutlet UINavigationController *navController;

 @end

 m

 #import "AppDelegate.h"

 @implementation AppDelegate

 @synthesize navigationController = _navigationController;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.backgroundColor = [UIColor whiteColor];

    //[self.window addSubview:self.navController.view];

    self.window.rootViewController = self.navController;

    [self.window makeKeyAndVisible];

    return YES;

 }

 - (void)applicationWillResignActive:(UIApplication *)application

 {  

 } 

 - (void)applicationDidEnterBackground:(UIApplication *)application

 {  

 }

 - (void)applicationWillEnterForeground:(UIApplication *)application

 {

 }

 - (void)applicationDidBecomeActive:(UIApplication *)application

 {

 }

 - (void)applicationWillTerminate:(UIApplication *)application

 {

 }

 @end



   #import <UIKit/UIKit.h>
   #import <AVFoundation/AVFoundation.h>
   #import <AudioToolbox/AudioToolbox.h>
   @class ViewController;
   @interface AppDelegate : UIResponder <UIApplicationDelegate>
   @property (strong, nonatomic) UIWindow *window;
   @property (strong, nonatomic) ViewController *viewController;
   @end

   #import "AppDelegate.h"
   #import "ViewController.h"
   @implementation AppDelegate
   @synthesize viewController = _viewController;
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
   {
      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
   }else{
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
   }
            self.window.backgroundColor = [UIColor whiteColor];
            self.window.rootViewController = self.viewController;
            AVAudioSession *audioSession = [AVAudioSession sharedInstance];
            NSError *categoryError = nil;
            BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers 
                                                                                                                                     error:&categoryError];
            if (!success) {
                  NSLog(@"%@",  [categoryError localizedDescription]);
                 exit(1);
   }
            NSError *activationError = nil;
             success = [audioSession setActive:YES error:&activationError];
            if (!success) {
                 NSLog(@"%@",  [activationError localizedDescription]);
                 exit(1);
   }
            [UIAlertView beginAnimations:nil context:nil];
            [UIAlertView setAnimationDuration:0.5];
            [self.window makeKeyAndVisible];
             return YES;
   }
   - (void)applicationWillResignActive:(UIApplication *)application
  {
  }
  - (void)applicationDidEnterBackground:(UIApplication *)application
  { 
  }
  - (void)applicationWillEnterForeground:(UIApplication *)application
  {
  }
  - (void)applicationDidBecomeActive:(UIApplication *)application
  {
  }
  - (void)applicationWillTerminate:(UIApplication *)application
  {
  }
  @end

 
    UITableView  
 main.m
 #import <UIKit/UIKit.h>

 #import "AppDelegate.h"

 int main(int argc, char *argv[])

 {

 @autoreleasepool {

     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

 }

 }

 AppDelegate.h

 #import <UIKit/UIKit.h>

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) UIWindow *window;

 @property(strong, nonatomic) IBOutlet UINavigationController *navigationController;

 @end

 AppDelegate.m

 #import "AppDelegate.h"

 @implementation AppDelegate

 @synthesize navigationController = _navigationController;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 {

     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

     self.window.backgroundColor = [UIColor whiteColor];

     //[self.window addSubview:self.navigationController.view];

     self.window.rootViewController = self.navigationController;

    [self.window makeKeyAndVisible];

    return YES;

 }

 - (void)applicationWillResignActive:(UIApplication *)application

 {

 }

 - (void)applicationDidEnterBackground:(UIApplication *)application

 {

 }

 - (void)applicationWillEnterForeground:(UIApplication *)application

 {

 }

 - (void)applicationDidBecomeActive:(UIApplication *)application

 {

 }

 - (void)applicationWillTerminate:(UIApplication *)application

 {

 }

 @end

 RootViewController.h

 #import <UIKit/UIKit.h>

 @interface RootViewController : UIViewController

 <UITableViewDelegate, UITableViewDataSource>

 @property (nonatomic,strong) NSArray *tableList, *colorList;

 @property (nonatomic,strong) NSArray *labelInfo;

 @property (nonatomic,strong) NSArray *textFiles;

 @property (nonatomic,strong) NSArray *urlList;

 @end

 RootViewController.m
 #import "RootViewController.h"

 #import "DetailViewController.h"

 @interface RootViewController ()

 @end

 @implementation RootViewController

 @synthesize tableList, colorList;

 @synthesize labelInfo;

 @synthesize textFiles;

 @synthesize urlList;

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

 {

     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

     if (self) {

         // Custom initialization

     }

     return self;

 }

 - (void)viewDidLoad

 {

     [super viewDidLoad];

self.navigationController.navigationBar.tintColor = [UIColor blackColor];

//self.navigationController.navigationBar.translucent = YES;

self.title = NSLocalizedString(@"Table View", @"Table View");

//self.title = NSLocalizedString(<#key#>, <#comment#>)

self.tableList = [[NSArray alloc] initWithObjects:@"TableView Section 1", @"TableView Section 2", @"TableView                Section 3"@"TableView Section 4", @"TableView Section 5",@"TableView Section 6",@"TableView Section 7", nil];

self.colorList = [[NSArray alloc] initWithObjects:@"Row1.png", @"Row2.png", @"Row3.png",

                                                          @"Row4.png", @"Row5.png",@"Row6.png", @"Row7.png", nil];

self.labelInfo = [[NSArray alloc] initWithObjects:

  @"File 1",

  @"File 2",

  @"File 3",

  @"File 4",

  @"File 5", nil];

self.textFiles = [[NSArray alloc] initWithObjects:

  @"Description 1",

  @"Description 2",

  @"Description 3",

  @"Description 4",

  @"Description 5", nil];

self.urlList = [[NSArray alloc] initWithObjects:

  @"http://google.com",

  @"http://cnn.com",

          @"http://twitter.com",

  @"http://facebook.com",

  @"http://hotmail.com", nil];

 }

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

 {

     return 1;

 }

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

 {

     return [self.tableList count];

 }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

 {

     static NSString *CellIdentifier = @"Cell";

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

     if (cell == nil) {

         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    cell.textLabel.text = [self.tableList objectAtIndex:indexPath.row];

    cell.imageView.image = [UIImage imageNamed:[self.colorList objectAtIndex:indexPath.row]];

    cell.textLabel.textColor = [UIColor redColor];

 if (indexPath.row == 3) {

cell.textLabel.textColor = [UIColor blueColor];
     }

     return cell;

 }

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

 {
        NSString *selectedLabelFile = [[NSString alloc] init];

NSString *files = [[NSString alloc] init];

NSString *url = [[NSString alloc] init];

     switch (indexPath.row) {

        case 0:

            selectedLabelFile = @"File 1";

    files =  @"Description 1";

    url =   @"http://google.com";

            break;

        case 1:

            selectedLabelFile = @"File 2";

    files =  @"Description 2";

    url = @"http://cnn.com";

            break;

        case 2:

    selectedLabelFile = @"File 3";

    files =  @"Description 3";

    url = @"http://twitter.com";

            break;

        case 3:

    selectedLabelFile = @"File 4";

    files =  @"Description 4";

    url = @"http://facebook.com";

            break;

        case 4:

    selectedLabelFile = @"File 5";

    files =  @"Description 5";

            url = @"http://hotmail.com";

            break;

        default:

            break;

    }

    DetailViewController *detailView = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:             [NSBundle mainBundle]];

 detailView.labelDescription = selectedLabelFile;

 detailView.pushedFiles = files;

 detailView.pushedURL = url;

[self.navigationController pushViewController:detailView animated:YES];

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];   

 }

 @end

 DetailViewController.h

 #import <UIKit/UIKit.h>

 @interface DetailViewController : UIViewController

 @property (weak, nonatomic) IBOutlet UILabel *label;

 @property (strong, nonatomic) IBOutlet UITextView *textView;

 @property (strong, nonatomic) IBOutlet UIWebView *browser;

 @property (strong, nonatomic) NSString *labelDescription;

 @property (strong, nonatomic) NSString *pushedFiles;

 @property (strong, nonatomic) NSString *pushedURL;

 @end

 DetailViewController.m

 #import "DetailViewController.h"

 @interface DetailViewController ()

 @end

 @implementation DetailViewController

 @synthesize  labelDescription;

 @synthesize label;

 @synthesize pushedFiles;

 @synthesize textView;

 @synthesize browser;

 @synthesize pushedURL;

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

 {

     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

     if (self) {

         // Custom initialization
    }

    return self;

 }

 - (void)viewDidLoad

 {

     [super viewDidLoad];

self.label.text = self.labelDescription;

self.textView.text = self.pushedFiles;

NSURL *url = [NSURL URLWithString:self.pushedURL];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[self.browser loadRequest:request];

 }

 - (void)didReceiveMemoryWarning

 {

      [super didReceiveMemoryWarning]; 

 }

 @end

    UIPickerView - Programmatic  
 AppDelegate.h
 #import <UIKit/UIKit.h> 

 @class PickerViewController;

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) IBOutlet UIWindow *window;

 @property (strong, nonatomic) IBOutlet PickerViewController *pickerViewController;

 @end
 AppDelegate.m

 #import "AppDelegate.h"

 #import "PickerViewController.h"

 @implementation AppDelegate

 @synthesize pickerViewController = _pickerViewController;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.rootViewController = self.pickerViewController;

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

 }

 - (void)applicationWillResignActive:(UIApplication *)application

 {
 }

 - (void)applicationDidEnterBackground:(UIApplication *)application

 {

 }

 - (void)applicationWillEnterForeground:(UIApplication *)application

 {

 }

 - (void)applicationDidBecomeActive:(UIApplication *)application

 {

 }

 - (void)applicationWillTerminate:(UIApplication *)application

 {

 }

 @end

 PickerViewController.h

 #import <UIKit/UIKit.h>

 @interface PickerViewController : UIViewController

 <UIPickerViewDelegate, UIPickerViewDataSource>

 @property(strong, nonatomic)IBOutlet UIPickerView *picker;

 @property(strong, nonatomic)IBOutlet NSMutableArray *mArray;

 @property(strong, nonatomic)IBOutlet UIButton *cancelButton;

 @property(strong, nonatomic) IBOutlet UIButton *pickerON;

 @property(weak, nonatomic) IBOutlet UILabel *pickerInfo;

 -(IBAction)showPicker:(UIButton *)sender;

 @end

 PickerViewController.m

 #import "PickerViewController.h"

 @interface PickerViewController ()

 @end

 @implementation PickerViewController

 @synthesize picker;

 @synthesize mArray;

 @synthesize cancelButton;

 @synthesize pickerON;

 @synthesize pickerInfo;

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

 {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

     if (self) {

    }

    return self;

 }

 - (void)viewDidLoad

 {

     [super viewDidLoad];

      self.mArray=[[NSMutableArray alloc] initWithObjects:@"Canada",@"US",@"Netherlands",@"Poland",@"Sweden",

                                              @"Mexico",@"Germany",@"Italy",@"Australia",@"Switzerland",nil];

 }

 - (void)didReceiveMemoryWarning

 {

     [super didReceiveMemoryWarning];

 }

 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

    NSUInteger numRows = 10;

    return numRows;

 }

 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {

    return 1;

 }

 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

 {

    [self.pickerInfo setText:[NSString stringWithFormat:@"%@",[self.mArray objectAtIndex:[pickerView
    
selectedRowInComponent:0]]]];
 }

 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

 {
    return [self.mArray objectAtIndex:row];

 }

 - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {

    CGFloat componentWidth = 0;

componentWidth = 180.0;

    return componentWidth;

 }

 -(IBAction)showPicker:(UIButton *)sender

 {

     self.picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 220.0, 330.0, 300.0)];

     [self.view addSubview:self.picker];

     self.picker.delegate = self;

     self.picker.showsSelectionIndicator = YES;   

     self.cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

     [self.cancelButton addTarget:self

                           action:@selector(removeObject:)

                 forControlEvents:UIControlEventTouchDown];

     self.cancelButton.frame = CGRectMake(267.0,320.052.0, 30.0);

     UIImage *image = [UIImage imageNamed:@"Cancel.png"];

     [self.cancelButton setImage:image forState:UIControlStateNormal];

     [self.view addSubview:self.cancelButton];

 }

 -(IBAction)removeObject:(id)sender

 {

     [self.picker removeFromSuperview];

     [self.cancelButton removeFromSuperview];

 }

 @end



   UIView (View / SubViews)   
 AppDelegate.h

 #import <UIKit/UIKit.h>

 @class HierarchyViewController;

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) UIWindow *window;

 @property (strong, nonatomic) HierarchyViewController *viewController;

 @end

 AppDelegate.m

 #import "AppDelegate.h"

 #import "HierarchyViewController.h"

 @implementation AppDelegate

 @synthesize viewController = _viewController;

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

 {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.viewController = [[HierarchyViewController alloc] initWithNibName:nil bundle:nil];

    self.window.backgroundColor = [UIColor whiteColor];

    self.window.rootViewController = self.viewController;
   [self.window makeKeyAndVisible];

    return YES;

 }

 - (void)applicationWillResignActive:(UIApplication *)application

 {

 }

 - (void)applicationDidEnterBackground:(UIApplication *)application

 {

 }

 - (void)applicationWillEnterForeground:(UIApplication *)application

 {

 }

 - (void)applicationDidBecomeActive:(UIApplication *)application

 {

 }

 - (void)applicationWillTerminate:(UIApplication *)application

 {

 }

 @end

 HierarchyViewController.h

 #import <UIKit/UIKit.h>

 #import "MainViewController.h"

 #import "SubView1.h"

 #import "SubView2.h"

 #import "SubView3.h"

 @interface HierarchyViewController : UIViewController

 @property (strong, nonatomic) MainViewController *mainView;

 @property (strong, nonatomic) SubView1 *subView1;

 @property (strong, nonatomic) SubView2 *subView2;

 @property (strong, nonatomic) SubView3 *subView3;

 @end

 HierarchyViewController.m

 #import "HierarchyViewController.h"

 @interface HierarchyViewController ()

 @end

 @implementation HierarchyViewController

 @synthesize mainView;

 @synthesize subView1;

 @synthesize subView2;

 @synthesize subView3;

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

 {

     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

     if (self) {

 self.mainView = [[MainViewController alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

 self.view = self.mainView;
         self.mainView.backgroundColor = [UIColor grayColor];

 CGRect subView1Frame = CGRectMake(0, 50, 200, 200);

         CGRect subView2Frame = CGRectMake(20, 200, 250, 250);

 CGRect subView3Frame = CGRectMake(150, 400, 100, 40);

 self.subView1 = [[SubView1 alloc] initWithFrame:subView1Frame];

         self.subView2 = [[SubView2 alloc] initWithFrame:subView2Frame];

 self.subView3 = [[SubView3 alloc] initWithFrame:subView3Frame];

[self.view addSubview:self.subView1];
        [self.view addSubview:self.subView1];

        [self.view addSubview:self.subView1];

 self.subView1.backgroundColor = [UIColor blueColor];

         self.subView2.backgroundColor = [UIColor yellowColor];

 self.subView3.backgroundColor = [UIColor greenColor];

    }

    return self;

 }

 - (void)viewDidLoad

 {

     [super viewDidLoad];

 }

 - (void)didReceiveMemoryWarning

 {

     [super didReceiveMemoryWarning];

 }

 @end

 MainViewController.h

 #import <UIKit/UIKit.h>

 @interface MainViewController : UIView

 @end

 MainViewController.m

 #import "MainViewController.h"

 @implementation MainViewController

 - (id)initWithFrame:(CGRect)frame

 {

     self = [super initWithFrame:frame];

     if (self) {

 CGRect labelFrame = CGRectMake(0, 0, 80, 25);

         UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];

         label.text = @"MainView";

         label.backgroundColor = [UIColor redColor];

         [self addSubview:label];

     }

     return self;

 }

 @end

 SubView1.h

 #import <UIKit/UIKit.h>

 @interface SubView1 : UIView

 @end

 SubView1.m

 #import "SubView1.h"

 @implementation SubView1

 - (id)initWithFrame:(CGRect)frame

 {

     self = [super initWithFrame:frame];

     if (self) {

 CGRect labelFrame = CGRectMake(0, 0, 100, 25);

         UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];

         label.text = @"SubView 1";

         label.backgroundColor = [UIColor redColor];

         [self addSubview:label];

     }

     return self;
 }

 @end

 SubView2.h

 #import <UIKit/UIKit.h>

 @interface SubView2 : UIView

 @end

 SubView2.m

 #import "SubView2.h"

 @implementation SubView2

 - (id)initWithFrame:(CGRect)frame

 {

     self = [super initWithFrame:frame];

     if (self) {

 CGRect labelFrame = CGRectMake(0, 0, 100, 25);

         UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];

         label.text = @"SubView 2";

         label.backgroundColor = [UIColor redColor];

         [self addSubview:label];

     }

     return self;

 }

 @end

 SubView3.h

 #import <UIKit/UIKit.h>

 @interface SubView3 : UIView

 @end

 SubView3.m

 #import "SubView3.h"

 @implementation SubView3

 - (id)initWithFrame:(CGRect)frame

 {

     self = [super initWithFrame:frame];

     if (self) {

 CGRect labelFrame = CGRectMake(0, 0, 100, 25);

         UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];

         label.text = @"SubView 3";

         label.backgroundColor = [UIColor redColor];

         [self addSubview:label];

     }

     return self;

 }

 @end


  Display Message - NSString / UIButton  
 h

 #import <UIKit/UIKit.h>
 @interface
ViewController : UIViewController
 {
       IBOutlet
UILabel *label;
 }
 @property
(nonatomic, retain) IBOutlet UILabel *label;
 - (IBAction)showMessage:(id)sender;
 @end

 m
 #import "ViewController.h"

 @interface ViewController ()
 @end

 @implementation
ViewController
 @synthesize
label;
 - (
IBAction)showMessage:(id)sender
 {
 NSString
*message = [[NSString alloc] initWithString:@"Hello World"];
 label.text = message;
 [message release];
 [
label release];
 }

 - (
void)viewDidLoad
 {
      [super viewDidLoad];    
 }
 - (
void)didReceiveMemoryWarning
 {
       [super didReceiveMemoryWarning];     
 }

 - (void)dealloc
 {
        [label release];
        [super dealloc];
 }

 @end


    Display Image - UIButton 
  
 
h

 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController

 {

IBOutlet UIImageView *imageView;

NSInteger currentValue;

 }

 @property (nonatomic, retain) IBOutlet UIImageView *imageView;

 - (IBAction)displayImage:(id)sender;

 @end

 m

 #import "ViewController.h"

 @interface ViewController ()

 @end

 @implementation ViewController

 @synthesize imageView;

 - (IBAction)displayImage:(id)sender

 {

currentValue = 0;

imageView.image = [UIImage imageNamed:@"111.png"];

 }

 - (void)viewDidLoad

 {

    [super viewDidLoad];

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];

 }

 @end


  Saving Data - NSUser Defaults  
 h

 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController{

IBOutlet UITextField *textField;

 }

 @property (nonatomic, retain) IBOutlet UITextField *textField;

 - (IBAction)saveData:(id)sender;

 @end

 m

 #import "ViewController.h"

 @interface ViewController ()

 @end

 @implementation ViewController

 @synthesize textField;

 - (IBAction)saveData:(id)sender{

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setObject:textField forKey:@"key1010"];

[defaults synchronize];

[textField resignFirstResponder];

 } 

 - (void)viewDidLoad

 {

    [super viewDidLoad];

textField.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"key1010"];

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];   

 } 

 @end

  Page Switch - XIB File - Protocol / Delegation   
 h

 #import "InfoViewController.h"

 @interface MainViewController : UIViewController <InfoViewControllerDelegate>

 - (IBAction)showInfo:(id)sender;

 @end

 m

 #import "MainViewController.h"

 @interface MainViewController ()

 @end

 @implementation MainViewController

 - (void)viewDidLoad

 { 

    [super viewDidLoad];

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];  

 }

 - (void)infoViewControllerDidFinish:(InfoViewController *)controller

 {

    [self dismissViewControllerAnimated:YES completion:nil];

 }

 - (IBAction)showInfo:(id)sender

 {    

    InfoViewController *controller = [[[InfoViewController alloc] initWithNibName:@"InfoViewController" bundle:nil]                     autorelease];

    controller.delegate = self;

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    [self presentViewController:controller animated:YES completion:nil];

 }

 @end

 h  (Page2)

 #import <UIKit/UIKit.h>

 @class InfoViewController;

 @protocol InfoViewControllerDelegate

 - (void)infoViewControllerDidFinish:(InfoViewController *)controller;

 @end

 @interface InfoViewController : UIViewController

 @property (assign, nonatomic) id <InfoViewControllerDelegate> delegate;

 - (IBAction)back:(id)sender;

 @end

 m (Page2)

 #import "InfoViewController.h"

 @interface InfoViewController ()

 @end

 @implementation InfoViewController

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

 {

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {    

    }

    return self;

 }

 - (void)viewDidLoad

 {

    [super viewDidLoad];   

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];  

 }

 - (IBAction)back:(id)sender

 {

    [self.delegate infoViewControllerDidFinish:self];

 }

 @end

    UISlider Control  
 h

 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController{

IBOutlet UILabel *label;

IBOutlet UISlider *slider;

 }

 @property (retain, nonatomic) IBOutlet UILabel *label;

 @property (retain, nonatomic) IBOutlet UISlider *slider;

 - (IBAction)setValue:(id)sender;

 @end

 m

 #import "ViewController.h"

 @interface ViewController ()

 @end

 @implementation ViewController

 @synthesize label, slider;

 - (IBAction)setValue:(id)sender{

float currentValue;

currentValue = [slider value];

NSString *value = [[NSString alloc] initWithFormat:@"Value is : %.2f", currentValue];

label.text = value;

[value release];

 }

 - (void)viewDidLoad

 {

    [super viewDidLoad];

 }

 - (void)didReceiveMemoryWarning

 {

    [super didReceiveMemoryWarning];   

 }

 - (void)dealloc
 {
        [label release];
        [super dealloc];
 }
 @end


  Create Class (Setter/Getter)  
 h (View Controller) 
 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController

 - (IBAction)action:(id)sender;
 @end

 m (View Controller)

 #import "ViewController.h"
 #import "Bike.h"
 @interface ViewController ()
 @end
 @implementation ViewController
 - (void)viewDidLoad
 {
     [super viewDidLoad];

 }
  - (void)didReceiveMemoryWarning
  {
     [super didReceiveMemoryWarning];
  }
  - (IBAction)action:(id)sender {
        Bike *motorcycle;
                  motorcycle = [Bike alloc];
[motorcycle setterMake:@" Suzuki "];
[motorcycle setterModel:@" Hayabusa "];
[motorcycle setterYear:2007];
[motorcycle startingMileage];
NSString *bikeMake = [motorcycle getterMake];
NSString *bikeModel = [motorcycle getterModel];
int bikeYear = [motorcycle getterYear];
[motorcycle setterKilometersDriven:1225.6];
[motorcycle setterKilometersDriven:200.1];
[motorcycle setterKilometersDriven:1509.8];
[motorcycle setterKilometersDriven:12180.3];
NSLog(@" bike make is %@ ", bikeMake);
NSLog(@" bike model is %@ ", bikeModel);
NSLog(@" year is %d "bikeYear);
NSLog(@" driven kilometers is %.1f ", [motorcycle getterKilometers]);
  }
  @end
 h (Bike class)

 #import <Foundation/Foundation.h>

 @interface Bike : NSObject{

NSString *make;

NSString *model;

int year;

float kilometersDriven;

 }

 -(void) setterMake:(NSString *)makeOfBike;

 -(void) setterModel:(NSString *)modelOfBike;

 -(void) setterYear:(int)yearOfBike;

 -(void) setterKilometersDriven:(float)kilometersDrivenOnBike;

 -(void) startingMileage;

 -(NSString *)getterMake;

 -(NSString *)getterModel;

 -(int)getterYear;

 -(float)getterKilometers;

 @end

 m (Bike class)

 #import "Bike.h"

 @implementation Bike

 -(void) setterMake:(NSString *)makeOfBike{

make = makeOfBike;

 }

 -(void) setterModel:(NSString *)modelOfBike{

model = modelOfBike;

 }

 -(void) setterYear:(int)yearOfBike{

year = yearOfBike;

 }

 -(void) setterKilometersDriven:(float)kilometersDrivenOnBike{

kilometersDriven += kilometersDrivenOnBike;

 }

 -(void) startingMileage{

kilometersDriven = 0;

 }

 -(NSString *)getterMake{

return make;

 }

 -(NSString *)getterModel{

return model;

 }

 -(int)getterYear{

return year;
 }

 -(float)getterKilometers{

return kilometersDriven;

 }

 @end



    Create Class (Properties)  
 h (View Controller)
 #import <UIKit/UIKit.h>

 @interface ViewController : UIViewController

 - (IBAction)action:(id)sender;

 @end
 m (View Controller)

 #import "ViewController.h"
 #import "Bike.h"
 @interface ViewController ()
 @end
 @implementation ViewController
 - (void)viewDidLoad
 {
     [super viewDidLoad];
 }
 - (void)didReceiveMemoryWarning
 {
     [super didReceiveMemoryWarning];    
 }
 - (IBAction)action:(id)sender {
Bike *motorcycle;
motorcycle = [Bike alloc];
[motorcycle startingMileage];
motorcycle.make  = @" Suzuki";
motorcycle.model  = @" Hayabusa";
motorcycle.year  = 2007;
NSString *bikeMake = motorcycle.make;
NSString *bikeModel = motorcycle.model;
NSLog(@" make is %@", bikeMake);
NSLog(@" model is %@", bikeModel);
NSLog(@" year is %d", motorcycle.year);
[motorcycle kilometersDriven:1007.1];
[motorcycle kilometersDriven:1290.0];
[motorcycle kilometersDriven:11209.7];
[motorcycle kilometersDriven:100.7];
NSLog(@" mileage is %.1f", motorcycle.kilometers);
 }
 @end

 h (Bike class)

 #import <Foundation/Foundation.h>

 @interface Bike : NSObject

 @property NSString *make;

 @property NSString *model;

 @property int year;

 @property float kilometers;

 -(void) kilometersDriven:(float)kilometersDrivenOnBike;

 -(void) startingMileage;

 @end

 m (Bike class)

 #import "Bike.h"
 @implementation Bike
 @synthesize make;
 @synthesize model;
 @synthesize year;
 @synthesize kilometers;
 -(void) kilometersDriven:(float)kilometersDrivenOnBike{
   kilometers += kilometersDrivenOnBike;
 }
 -(void) startingMileage{
 kilometers = 0;
 }
 @end