Tuesday, July 22, 2014

Custom Object Class

#import <Foundation/Foundation.h>

@interface Person : NSObject


@property(nonatomic,strong)NSString *firstName;
@property(nonatomic,strong)NSString *lastName;

-(id)initWithAdrianFirstName:(NSString*)firstName
                withLastName:(NSString*)lastName;
-(NSString*)description;


@end

#import "Person.h"

@implementation Person

-(id)initWithAdrianFirstName:(NSString *)firstName withLastName:(NSString *)lastName
{
    self=[super init];
    self.firstName=firstName;
    self.lastName=lastName;
    return self;
    
}

-(NSString*)description{
    
    return [NSString stringWithFormat:@"%@,%@",self.firstName,self.lastName];
}

@end


- (void)viewDidLoad
{
Person *p=[[Person alloc]initWithAdrianFirstName:@"dhanushka" withLastName:@"Adrian"] ;
    personLable.text=[p description];

}

Monday, July 21, 2014

Inter

http://www.cquestions.com/2011/08/prime-number-program-in-c-using.html

#include<stdio.h>

int isPrime(int,int);

int main(){

    int num,prime;

    printf("Enter a positive number: ");
    scanf("%d",&num);

    prime = isPrime(num,num/2);

   if(prime==1)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);

   return 0;
}

int isPrime(int num,int i){

    if(i==1){
        return 1;
    }else{
       if(num%i==0)
         return 0;
       else
         isPrime(num,i-1);
    }
}

Tuesday, July 15, 2014

Create Gradient UIView in IOS

01. Create NSObject Class Call "GradientBackground" and add this code

.h

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>


@interface GradientBackground : NSObject


+(CAGradientLayer*) yellowGradient;
+(CAGradientLayer*) greenGradient;
+(CAGradientLayer*) orangeGradient;
+(CAGradientLayer*) redGradient;

@end

----------------------------------------------------------------------
.m


#import "GradientBackground.h"

@implementation GradientBackground

+ (CAGradientLayer*) yellowGradient {
   
    UIColor *darkOp =
    [UIColor colorWithRed:229/255.0f green:184/255.0f blue:0/255.0f alpha:1.0];
    UIColor *lightOp =
    [UIColor colorWithRed:255/255.0f green:204/255.0f blue:0/255.0f alpha:1.0];
   
    // Create the gradient
    CAGradientLayer *gradient = [CAGradientLayer layer];
   
    // Set colors
    gradient.colors = [NSArray arrayWithObjects:
                       (id)lightOp.CGColor,
                       (id)darkOp.CGColor,
                       nil];
   
   
   
   
   
    CAGradientLayer *headerLayer = [CAGradientLayer layer];
    headerLayer.colors =   gradient.colors;
   
   
    return headerLayer;
   
}

+ (CAGradientLayer*) greenGradient {
   
    UIColor *darkOp =
    [UIColor colorWithRed:86/255.0f green:178/255.0f blue:73/255.0f alpha:1.0];
   
    UIColor *lightOp =
    [UIColor colorWithRed:113/255.0f green:206/255.0f blue:101/255.0f alpha:1.0];
   
   
    // Create the gradient
    CAGradientLayer *gradient = [CAGradientLayer layer];
   
    // Set colors
    gradient.colors = [NSArray arrayWithObjects:
                       (id)lightOp.CGColor,
                       (id)darkOp.CGColor,
                       nil];
   
   
   
   
   
    CAGradientLayer *headerLayer = [CAGradientLayer layer];
    headerLayer.colors =   gradient.colors;
   
   
    return headerLayer;
   
}
+ (CAGradientLayer*) orangeGradient {
    //247,157,97  223,142,88
   
   
    UIColor *darkOp =
    [UIColor colorWithRed:223/255.0f green:142/255.0f blue:88/255.0f alpha:1.0];
    UIColor *lightOp =
    [UIColor colorWithRed:247/255.0f green:157/255.0f blue:97/255.0f alpha:1.0];
   
    // Create the gradient
    CAGradientLayer *gradient = [CAGradientLayer layer];
   
    // Set colors
    gradient.colors = [NSArray arrayWithObjects:
                       (id)lightOp.CGColor,
                       (id)darkOp.CGColor,
                       nil];
   
   
   
   
   
    CAGradientLayer *headerLayer = [CAGradientLayer layer];
    headerLayer.colors =   gradient.colors;
   
   
    return headerLayer;
   
}

+ (CAGradientLayer*) redGradient {
    /*
     243,49,64
     195,27,40
    
     
     */
   
    UIColor *darkOp =
    [UIColor colorWithRed:195/255.0f green:27/255.0f blue:40/255.0f alpha:1.0];
    UIColor *lightOp =
    [UIColor colorWithRed:243/255.0f green:49/255.0f blue:64/255.0f alpha:1.0];
   
    // Create the gradient
    CAGradientLayer *gradient = [CAGradientLayer layer];
   
    // Set colors
    gradient.colors = [NSArray arrayWithObjects:
                       (id)lightOp.CGColor,
                       (id)darkOp.CGColor,
                       nil];
   
   
   
   
   
    CAGradientLayer *headerLayer = [CAGradientLayer layer];
    headerLayer.colors =   gradient.colors;
   
   
    return headerLayer;
   
}

@end

02. Add this code to your ViewController

.h
---------------------------------------------------------

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property(nonatomic,strong)IBOutlet UIView *adrianView;
@property(nonatomic,strong)IBOutlet UIView *adrianView1;
@property(nonatomic,strong)IBOutlet UIView *adrianView2;
@property(nonatomic,strong)IBOutlet UIView *adrianView3;

@end


.m
---------------------------------------------------
#import "ViewController.h"
#import "GradientBackground.h"

@implementation ViewController
@synthesize adrian,adrian1,adrian2,adrian3;


#pragma mark - View lifecycle

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

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //Add gradient background

    CAGradientLayer *bgLayer = [BackgroundLayer orangeGradient];
    bgLayer.frameadrianView.bounds;
    [adrianView.layer insertSublayer:bgLayer atIndex:0];
   
    CAGradientLayer *bgLayer1 = [BackgroundLayer redGradient];
    bgLayer1.frameadrianView1.bounds;
    [adrianView1.layer insertSublayer:bgLayer1 atIndex:0];
   
    CAGradientLayer *bgLayer2 = [BackgroundLayer yellowGradient];
    bgLayer2.frameadrianView2.bounds;
    [adrianView2.layer insertSublayer:bgLayer2 atIndex:0];
   
   
    CAGradientLayer *bgLayer3 = [BackgroundLayer greenGradient];
    bgLayer3.frameadrianView3.bounds;
    [adrianView3.layer insertSublayer:bgLayer3 atIndex:0];
   
   
   
   
}

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

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

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
03. Run the project

Connect the outlet in .xib file

04. Run the project