To demonstrate the creation of the Custom Controls using objective c


Your Description HereThis tutorial is used to show how to create the custom views in objective c.

 

 

1.  Open the xcode & choose "File->New Project".

2.  Select "window-based-Aapplication" from left menu .

3.  Name your project as "CustomControls" and save the project.

4.  Then  select "CustomControlsAppDelegate.h" file from the left side menu or group and files. Then enter the following :

 

#import <UIKit/UIKit.h>

 

@interface CustomControlsAppDelegate : NSObject <UIApplicationDelegate> {

        UIWindow *window;

UITextField *textField;

UITextField *textFieldOne;

UILabel *result;

}

 

@property(retain,nonatomic)UITextField *textField;

@property(retain,nonatomic)UITextField *textFieldOne;

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

@property (nonatomic, retain) UILabel *result;

@end

 

 

 

 

 

5. Then  select "CustomControlsAppDelegate.m" file from the left side menu or group and files.

 

#import "CustomControlsAppDelegate.h"

 

@implementation CustomControlsAppDelegate

 

@synthesize window,textField,textFieldOne,result;

 

 

#pragma mark -

#pragma mark Application lifecycle

 

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

    

    // Override point for customization after application launch.

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(10, 50, 100, 40)];

label.textColor = [UIColor blueColor];

label.backgroundColor =[UIColor cyanColor];

        label.textAlignment = UITextAlignmentLeft

label.text =@"First";

[view addSubview:label];

textField = [[UITextField alloc]initWithFrame:CGRectMake(130, 50,100 ,30)];

textField.borderStyle =UITextBorderStyleRoundedRect;

textField.textColor = [UIColor  blackColor];

[view addSubview:textField];

UILabel *label1 =[[UILabel alloc] initWithFrame:CGRectMake(10, 100, 100,40)];

label1.textColor = [UIColor blueColor];

  label1.backgroundColor =[UIColor cyanColor];

label1.textAlignment = UITextAlignmentLeft

label1.text =@"Second";

[view addSubview:label1];

textFieldOne =[[UITextField alloc]initWithFrame:CGRectMake(130, 100, 100,30)];

textFieldOne.borderStyle =UITextBorderStyleRoundedRect;

textFieldOne.textColor =[UIColor blackColor];

[view addSubview:textFieldOne];

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

button.frame=CGRectMake(130,200,100,40);

[button setTitle:@"Add" forState:UIControlStateNormal];

//button.backgroundColor=[UIColor blueColor];

[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 

[button addTarget:self  action:@selector(addition) forControlEvents:UIControlEventTouchUpInside];

[view addSubview:button];

result =[[UILabel alloc] initWithFrame:CGRectMake(10, 150, 100,40)];

result.textColor = [UIColor redColor];

         result.textAlignment = UITextAlignmentLeft

result.backgroundColor =[UIColor cyanColor];

result.text =@"Result";

[view addSubview:result];

window.backgroundColor = [UIColor cyanColor];

[window addSubview:view];

         [window makeKeyAndVisible];

    return YES;

}

 

 

-(void)addition

{

int x =[textField.text intValue]+[textFieldOne.text intValue];

result.text=[[NSString alloc] initWithFormat:@"%d",x];

NSLog(@"%i",x);

}

 

7. Click on the Built and Run tool and save it. Now you will have an output in front of you.

 

 



(5) Responses to this post

Lavonn May 04 2011 at 23:49:00

You have shed a ray of sunshine into the forum. Tankhs!

vsjnmlx May 06 2011 at 06:27:24

UxJbFu , [url=http://ypeodghcfvew.com/]ypeodghcfvew[/url], [link=http://eenfgaconfef.com/]eenfgaconfef[/link], http://stzipxszydhn.com/

Alkantava Jul 08 2011 at 17:04:20

Yes, correctly.

whituittY Aug 10 2011 at 12:48:41

panasonicuyy Jan 18 2012 at 23:20:47

Taking care of that creates digital slr dslrs more advanced than the standard level together with fire might be the ability to shift photographic camera improved lenses. Basically no two photos should previously become identical. Every one problem in addi


Leave your comment here






User Login




New User Forgot password

Newsletter Subscribe

Advertisement

 
 
 
quick contact