计算objective-c器
《计算objective-c器》由会员分享,可在线阅读,更多相关《计算objective-c器(14页珍藏版)》请在装配图网上搜索。
1、#import ViewController.h/implementation ViewControllersynthesize outPut=_outPut,biao=_biao;synthesize Button0,Button2,Button3,Button4,Button5,Button6,Button1,Button7,Button8,Button9,jianButton,chuButton,addButton,chenButton,denButton,shanButton,dianButton,gui0Button;synthesize textFiele,aStr=aStr,bS
2、tr=bStr,abStr=abStr,ji=ji,cun=_cun,suan=_suan,ji2=ji2,ji3=ji3;-(void)dealloc/鍦ealloc涓敤瀹炰緥鍙橀噺鍚嶅瓧release aStr release;bStr release;abStr release; super dealloc;- (void)didReceiveMemoryWarning super didReceiveMemoryWarning; / Release any cached data, images, etc that arent in use.#pragma mark - View li
3、fecycle- (void)viewDidLoad super viewDidLoad; self.aStr=NSMutableString stringWithFormat:; self.ji=0; self.cun=0; self.biao=0; self.suan=0; self.ji3=0; /UIImage鍥剧墖 UIImageView 鍥剧墖瑙嗗浘 UIImage *image=UIImage imageNamed:dd.png; UIImageView *imageView=UIImageView alloc initWithImage:image; self.view add
4、Subview:imageView; imageView release; /UILable 鏍囩 _outPut=UILabel alloc initWithFrame:CGRectMake(20, 20, 290, 50); _outPut setText:0; _outPut setTextAlignment:UITextAlignmentRight; _outPut setTextColor:UIColor whiteColor; _outPut setBackgroundColor:UIColor clearColor; _outPut setFont:UIFont fontWith
5、Name:Didot size:40; self.view addSubview:_outPut; _outPut release; /UITextFile 鏂囨湰瀛楁 textField=UITextField alloc initWithFrame:CGRectMake(0, 0, 300, 20); textField setBackgroundColor:UIColor clearColor; textField setTextColor:UIColor whiteColor; textField addTarget:self action:selector(acc:) forCont
6、rolEvents:UIControlEventEditingDidEndOnExit; self.view addSubview:textField; textField release; /UIButton 鎸夐挳 (320-4*50)/5 320/4 Button7=UIButton buttonWithType:1; Button7 setFrame:CGRectMake(24, 95, 65, 65); Button7 setTitle:7 forState:UIControlStateNormal; Button7 setTitleColor:UIColor orangeColor
7、 forState:UIControlStateNormal; Button7 setTag:7; Button7 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button7; Button8=UIButton buttonWithType:1; Button8 setFrame:CGRectMake(98, 95, 65, 65); Button8 setTitle:8 forState:UIControlSt
8、ateNormal; Button8 setTitleColor:UIColor purpleColor forState:UIControlStateNormal; Button8 setTag:8; Button8 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button8; Button9=UIButton buttonWithType:1; Button9 setFrame:CGRectMake(172,
9、 95, 65, 65); Button9 setTitle:9 forState:UIControlStateNormal; Button9 setTitleColor:UIColor redColor forState:UIControlStateNormal; Button9 setTag:9; Button9 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button9; chuButton =UIButt
10、on buttonWithType:1; chuButton setFrame:CGRectMake(246, 95, 65, 65); chuButton setTitleColor:UIColor blueColor forState:UIControlStateNormal; chuButton setTag:10; chuButton setTitle:/ forState:UIControlStateNormal; chuButton addTarget:self action:selector(suanPressen:) forControlEvents:UIControlEven
11、tTouchUpInside; self.view addSubview:chuButton; / Button4=UIButton buttonWithType:1; Button4 setFrame:CGRectMake(24, 170, 65, 65); Button4 setTitle:4 forState:UIControlStateNormal; Button4 setTitleColor:UIColor redColor forState:UIControlStateNormal; Button4 setTag:4; Button4 addTarget:self action:s
12、elector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button4; Button5=UIButton buttonWithType:1; Button5 setFrame:CGRectMake(98, 170, 65, 65); Button5 setTitle:5 forState:UIControlStateNormal; Button5 setTitleColor:UIColor redColor forState:UIControlStateNormal;
13、 Button5 setTag:5; Button5 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button5; Button6=UIButton buttonWithType:1; Button6 setFrame:CGRectMake(172, 170, 65, 65); Button6 setTitle:6 forState:UIControlStateNormal; Button6 setTitleCo
14、lor:UIColor redColor forState:UIControlStateNormal; Button6 setTag:6; Button6 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button6; chenButton=UIButton buttonWithType:1; chenButton setFrame:CGRectMake(246, 170, 65, 65); chenButton
15、setTitle:* forState:UIControlStateNormal; chenButton setTitleColor:UIColor redColor forState:UIControlStateNormal; chenButton setTag:11; chenButton addTarget:self action:selector(suanPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:chenButton; / Button1=UIButton buttonWit
16、hType:1; Button1 setFrame:CGRectMake(24, 245, 65, 65); Button1 setTitle:1 forState:UIControlStateNormal; Button1 setTitleColor:UIColor redColor forState:UIControlStateNormal; Button1 setTag:1; Button1 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.v
17、iew addSubview:Button1; Button2=UIButton buttonWithType:1; Button2 setFrame:CGRectMake(98, 245, 65, 65); Button2 setTitle:2 forState:UIControlStateNormal; Button2 setTitleColor:UIColor redColor forState:UIControlStateNormal; Button2 setTag:2; Button2 addTarget:self action:selector(numberPressen:) fo
18、rControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button2; Button3=UIButton buttonWithType:1; Button3 setFrame:CGRectMake(172, 245, 65, 65); Button3 setTitle:3 forState:UIControlStateNormal; Button3 setTitleColor:UIColor blueColor forState:UIControlStateNormal; Button3 setTag:3; Butto
19、n3 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button3; jianButton=UIButton buttonWithType:1; jianButton setFrame:CGRectMake(246, 245, 65, 65); jianButton setTitle:- forState:UIControlStateNormal; jianButton setTitleColor:UIColor
20、blackColor forState:UIControlStateNormal; jianButton setTag:12; jianButton addTarget:self action:selector(suanPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:jianButton; / Button0=UIButton buttonWithType:1; Button0 setFrame:CGRectMake(24, 320, 65, 65); Button0 setTitle:0
21、 forState:UIControlStateNormal; Button0 setTitleColor:UIColor magentaColor forState:UIControlStateNormal; Button0 setTag:0; Button0 addTarget:self action:selector(numberPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:Button0; dianButton=UIButton buttonWithType:1; dianBut
22、ton setFrame:CGRectMake(98, 320, 65, 65); dianButton setTitle:. forState:UIControlStateNormal; dianButton setTitleColor:UIColor redColor forState:UIControlStateNormal; dianButton setTag:13; dianButton addTarget:self action:selector(dianPressen:) forControlEvents:UIControlEventTouchUpInside; self.vie
23、w addSubview:dianButton; shanButton=UIButton buttonWithType:1; shanButton setFrame:CGRectMake(172, 320, 65, 65); shanButton setTitle:Delete forState:UIControlStateNormal; shanButton setTitleColor:UIColor magentaColor forState:UIControlStateNormal; shanButton setTag:14; shanButton addTarget:self acti
24、on:selector(deletePressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:shanButton; addButton=UIButton buttonWithType:1; addButton setFrame:CGRectMake(246, 320, 65, 65); addButton setTitle:+ forState:UIControlStateNormal; addButton setTitleColor:UIColor redColor forState:UICon
25、trolStateNormal; addButton setTag:15; addButton addTarget:self action:selector(suanPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:addButton; / gui0Button=UIButton buttonWithType:1; gui0Button setFrame:CGRectMake(32, 395, 120, 65); gui0Button setTitle:娓呴浂 forState:UICont
26、rolStateNormal; gui0Button setTitleColor:UIColor redColor forState:UIControlStateNormal; gui0Button setTag:16; gui0Button addTarget:self action:selector(qinPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:gui0Button; denButton=UIButton buttonWithType:1; denButton setFrame
27、:CGRectMake(185, 395, 120, 65); denButton setTitle:= forState:UIControlStateNormal; denButton setTitleColor:UIColor redColor forState:UIControlStateNormal; denButton setTag:17; denButton addTarget:self action:selector(suanPressen:) forControlEvents:UIControlEventTouchUpInside; self.view addSubview:d
28、enButton; - (void)viewDidUnload super viewDidUnload; self.outPut=nil; self.textFiele=nil; self.Button0=nil;self.Button2=nil;self.Button3=nil;self.Button4=nil; self.Button5=nil;self.Button6=nil;self.Button7=nil;self.Button8=nil; self.Button9=nil;self.jianButton=nil;self.chuButton=nil; self.addButton=
29、nil; self.chenButton=nil;self.denButton=nil; self.shanButton=nil;self.dianButton=nil;self.gui0Button=nil; self.Button1=nil; / Release any retained subviews of the main view. / e.g. self.myOutlet = nil;- (void)viewWillAppear:(BOOL)animated super viewWillAppear:animated;- (void)viewDidAppear:(BOOL)ani
30、mated super viewDidAppear:animated;- (void)viewWillDisappear:(BOOL)animatedsuper viewWillDisappear:animated;- (void)viewDidDisappear:(BOOL)animatedsuper viewDidDisappear:animated;- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation / Return YES for supported or
31、ientations return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);/-(void)numberPressen:(UIButton *)sender if (self.outPut.text.length6) return; if (self.biao!=0) ji2=0;ji3=0; self.suan=1; if (self.biao=1) self.aStr=NSMutableString stringWithFormat:; self.outPut.text=aStr stringBy
32、AppendingFormat:%lu,sender.tag; self.aStr=NSMutableString stringWithFormat:%,self.outPut.text; self.biao=0; return; else / self.outPut.text=aStr stringByAppendingFormat:%lu,sender.tag; /self.aStr=NSMutableString stringWithFormat:%,self.outPut.text; self.aStr appendFormat:%lu,sender.tag; self.outPut
33、setText:self.aStr; return; -(void)suanPressen:(UIButton *)sender if(self.suan=0) return; if (self.ji=0) self.cun=self.outPut.text doubleValue; / if (self.ji=1) self.cun=self.cun+self.outPut.text doubleValue; if (self.ji=2) self.cun=self.cun-self.outPut.text doubleValue; if (self.ji=3) self.cun=self.
34、cun * self.outPut.text doubleValue; if (self.ji=4) self.cun=self.cun/self.outPut.text doubleValue; / if (sender.tag=15|sender.tag=17) self.ji=1; if (sender.tag=12|sender.tag=17) self.ji=2; if (sender.tag=11|sender.tag=17) self.ji=3; if (sender.tag=10|sender.tag=17) self.ji=4; self.biao=1; self.suan=
35、0; self.outPut.text=NSString stringWithFormat:%g,self.cun; -(void)qinPressen:(UIButton *)sender self.outPut setText:0; self.ji=0; self.cun=0; self.biao=0; self.suan=0; self.ji2=0; self.ji3=0; self.aStr=NSMutableString stringWithFormat:;-(void)dianPressen:(UIButton *)sender if (self.outPut.text=0&ji2
36、=0) self.aStr=NSMutableString stringWithFormat:0.; self.outPut setText:self.aStr; ji2=1; return; else if(ji3=0) ji3=1; self.aStr appendFormat:.; self.outPut.text=self.aStr; -(void)deletePressen:(UIButton *)sender if (self.outPut.text!=) self.aStr deleteCharactersInRange:NSMakeRange(self.aStr.length-
37、1, 1); self.outPut setText:self.aStr; if (self.aStr hasSuffix:.) ji2=0;ji3=0; -(void)acc:(id)sender textField resignFirstResponder;/ ViewController.h/ Calculator/ Created by bokan on 12-6-7./ Copyright (c) 2012骞?鑱傛柊55555. All rights reserved./#import interface ViewController : UIViewController /澹版槑涓
38、哄睘鎬悗瀵硅薄涓嶆秷澶眫灞炴篃涓嶄細娑堝鍦ealloc閿姣亊鎴栬呯敤allocinit鎵嬪姩閲婃斁/灏嗘槸璋冭瘯productedit schemeobject-cexception渚嬪寮傚父 NSMutableString *aStr; NSMutableString *bStr; NSMutableString *abStr; double a; double b; double aa; int ji2; int ji; UILabel *_outPut; UIButton *Button1; UIButton *Button2; UIButton *Button3; UIButton *
39、Button4; UIButton *Button5; UIButton *Button6; UIButton *Button7; UIButton *Button8; UIButton *Button9; UIButton *Button0; UIButton *denButton; UIButton *addButton; UIButton *jianButton; UIButton *dianButton; UIButton *gui0Button; UIButton *chenButton; UIButton *chuButton; UIButton *shanButton; UITe
40、xtField *textField;property(nonatomic,retain)NSMutableString *aStr;property(nonatomic,retain)NSMutableString *bStr;property(nonatomic,retain)NSMutableString *abStr;property(nonatomic,assign)int ji,biao,suan,ji2,ji3;property(nonatomic,retain)UILabel *outPut;property(nonatomic,retain)UIButton *Button1
41、;property(nonatomic,retain)UIButton *Button2;property(nonatomic,retain)UIButton *Button3;property(nonatomic,retain)UIButton *Button4;property(nonatomic,retain)UIButton *Button5;property(nonatomic,retain)UIButton *Button6;property(nonatomic,retain)UIButton *Button7;property(nonatomic,retain)UIButton
42、*Button8;property(nonatomic,retain)UIButton *Button9;property(nonatomic,retain)UIButton *Button0;property(nonatomic,retain)UIButton *denButton;property(nonatomic,retain)UIButton *addButton;property(nonatomic,retain)UIButton *jianButton;property(nonatomic,retain)UIButton *dianButton;property(nonatomi
43、c,retain)UIButton *gui0Button;property(nonatomic,retain)UIButton *chenButton;property(nonatomic,retain)UIButton *chuButton;property(nonatomic,retain)UIButton *shanButton;property(nonatomic,retain)UITextField *textFiele;property(assign,nonatomic)double cun;end/ AppDelegate.m/ Calculator/ Created by b
44、okan on 12-6-7./ Copyright (c) 2012骞?鑱傛柊55555. All rights reserved./#import AppDelegate.h#import ViewController.himplementation AppDelegatesynthesize window = _window;synthesize viewController = _viewController;- (void)dealloc _window release; _viewController release; super dealloc;- (BOOL)applicati
45、on:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions self.window = UIWindow alloc initWithFrame:UIScreen mainScreen bounds autorelease; / Override point for customization after application launch. self.viewController = ViewController alloc initWithNibName:ViewC
46、ontroller bundle:nil autorelease; /self.viewController.view.backgroundColor=UIColor blackColor; self.window.rootViewController = self.viewController; self.window makeKeyAndVisible; return YES;- (void)applicationWillResignActive:(UIApplication *)application /* Sent when the application is about to mo
47、ve from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throt
48、tle down OpenGL ES frame rates. Games should use this method to pause the game. */- (void)applicationDidEnterBackground:(UIApplication *)application /* Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your appli
49、cation to its current state in case it is terminated later. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. */- (void)applicationWillEnterForeground:(UIApplication *)application /* Called as part of the transition fro
50、m the background to the inactive state; here you can undo many of the changes made on entering the background. */- (void)applicationDidBecomeActive:(UIApplication *)application /* Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. */- (void)applicationWillTerminate:(UIApplication *)application /* Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. */endend
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。