iphone4 UI全用代码实现在

//

//  main.m

//  fahrenheit1

//

//  Created by h on 11-7-5.

//  Copyright 2011 __MyCompanyName__. All rights reserved.

//


#import <UIKit/UIKit.h>


#define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f


#define  BARBUTTON(TITLE,SELECTOR)  [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]



@interface HelloWordController:UIViewController

{

UITextField *field1;

UITextField *field2;

}

//@property(nonatomic,retain) IBOutlet UITextField *field1;

//@property(nonatomic,retain) IBOutlet UITextField *field2;

-(void) convert:(id)sender;

@end


@implementation HelloWordController

//@synthesize field1;

//@synthesize field2;

-(void) convert:(id)sender

{

float invalue= [[field1 text] floatValue];

float outvalue= (invalue-32.0f) * 5.0f /9.0f;

[field2 setText:[NSString stringWithFormat:@"%3.2f", outvalue]];

[field1 resignFirstResponder];

}


-(void)loadView

{UIView *contentView= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

self.view = contentView;

contentView.backgroundColor = [UIColor whiteColor];//

[contentView release];

UIImageView *iv = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"icon.png"]];


field1= [[UITextField alloc] initWithFrame:CGRectMake(185.0, 31.0, 97.0, 31.0)];

field1.borderStyle= UITextBorderStyleRoundedRect;

field1.keyboardType=UIKeyboardTypeNumbersAndPunctuation;

field1.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;

//field1.userInteractionEnabled=YES;

[self.view addSubview:iv];

iv.userInteractionEnabled=YES;

field2= [[UITextField alloc] initWithFrame:CGRectMake(185.0, 97.0, 97.0, 31.0)];

field2.borderStyle=UITextBorderStyleRoundedRect;

field2.enabled=NO;

field2.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;

UILabel *lable1= [[UILabel alloc] initWithFrame:CGRectMake(95.0, 34.0, 82.0, 21.0)];

lable1.text = @"Fahrenheit";

lable1.textAlignment=UITextAlignmentLeft;

lable1.textColor= [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:1.000];

lable1.backgroundColor= [UIColor clearColor];

UILabel *lable2= [[UILabel alloc] initWithFrame:CGRectMake(121.0, 102.0, 56.0, 21.0)];

lable2.text= @"Celsius";

lable2.textAlignment=UITextAlignmentLeft;

lable2.textColor= [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:1.00];

lable2.backgroundColor= [UIColor clearColor];

[self.view addSubview:field1];

[self.view addSubview:field2];

[self.view addSubview:lable1];

[self.view addSubview:lable2];

[field1 release];

[field2 release];

[lable1 release];

[lable2 release];

[iv release];

self.title=@"Converter";

self.navigationItem.rightBarButtonItem=BARBUTTON(@"Convert",@selector(convert:));

self.navigationController.navigationBar.tintColor=  [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f];

}

@end;


@interface fahrenheit1AppDelegate : NSObject <UIApplicationDelegate> {

  //  UIWindow *window;

}


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


@end



@implementation fahrenheit1AppDelegate



#pragma mark -

#pragma mark Application lifecycle


- (void)applicationDidFinishLaunching:(UIApplication *)application{    

    

    // Override point for customization after application launch.

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

    UINavigationController * nav= [[UINavigationController alloc] initWithRootViewController:[ [HelloWordController alloc]init] ];

[window addSubview:nav.view];

    [window makeKeyAndVisible];

    

   // return YES;

}

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

//{

// UIWindow *window= [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds] ];

//    UINavigationController * nav= [[UINavigationController alloc] initWithRootViewController:[ [HelloWordController alloc]init] ];

// [window addSubview:nav.view];

//    [window makeKeyAndVisible];

//    

// return YES;

//}

@end





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

    

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int retVal = UIApplicationMain(argc, argv, nil, @"fahrenheit1AppDelegate");

    [pool release];

    return retVal;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值