計(jì)算objective-c器.doc_第1頁
計(jì)算objective-c器.doc_第2頁
計(jì)算objective-c器.doc_第3頁
計(jì)算objective-c器.doc_第4頁
計(jì)算objective-c器.doc_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

#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,bStr=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 lifecycle- (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 addSubview: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 fontWithName: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:) forControlEvents: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 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:UIControlStateNormal; 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, 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 =UIButton 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:UIControlEventTouchUpInside; 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:selector(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; 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 setTitleColor: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 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 buttonWithType: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.view 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:) forControlEvents: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; Button3 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 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 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; dianButton 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.view 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 action: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:UIControlStateNormal; 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:UIControlStateNormal; 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: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:denButton; - (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=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)animated super viewDidAppear:animated;- (void)viewWillDisappear:(BOOL)animatedsuper viewWillDisappear:animated;- (void)viewDidDisappear:(BOOL)animatedsuper viewDidDisappear:animated;- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation / Return YES for supported orientations 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 stringByAppendingFormat:%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 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.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=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=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-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 /澹版槑涓哄睘鎬悗瀵硅薄涓嶆秷澶眫灞炴篃涓嶄細(xì)娑堝鍦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 *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; UITextField *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;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 *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(nonatomic,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 bokan 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)application:(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:ViewController bundle:nil autorelease; /self.viewController.view.backgroundColor=UIColor blackColor; self.window.rootViewController = self.viewController; self.window makeKeyAndVisible; return YES;- (void)applicationWillResignActive:(UIA

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論