IOS加法计算器

来源:互联网 发布:达芬奇调色软件官网 编辑:程序博客网 时间:2024/05/29 16:51
////  ViewController.m//  01-加法计算器////  Created by yibooo on 16/1/11.//  Copyright © 2016年 yibooo. All rights reserved.//#import "ViewController.h"@interface ViewController ()// 第一个文本框@property (nonatomic, weak) IBOutlet UITextField * num1TextField;// 第二个文本框@property (nonatomic, weak) IBOutlet UITextField * num2TextField;// 计算结果@property (nonatomic, weak) IBOutlet UILabel * resultLabel;- (IBAction) caculate;@end@implementation ViewController/* IBAction 1.相当于void 2.只有返回值类型,声明为IBAction的方法才有资格与storyboard连线 IBOutlet 他就是一个标识符,标示可与storyboard进行连线 *///计算- (IBAction) caculate{//  取出文本框的内容    NSString * num1Text = self.num1TextField.text;    NSString * num2Text = self.num2TextField.text;//  把字符串转换为int类型    NSInteger result = num1Text.intValue + num2Text.intValue;//  改变文本框的值    self.resultLabel.text = [NSString stringWithFormat:@"%ld", (long)result];//   退出键盘//    [self.num1TextField resignFirstResponder];//    [self.num2TextField resignFirstResponder];//    只要是自己或自己的子控件呼叫出来的键盘,都可以通过这个方法来退出键盘    [self.view endEditing:YES];}@end
////  ViewController.m//  01-加法计算器////  Created by yibooo on 16/1/11.//  Copyright © 2016年 yibooo. All rights reserved.//#import "ViewController.h"@interface ViewController ()// 第一个文本框@property (nonatomic, weak) IBOutlet UITextField * num1TextField;// 第二个文本框@property (nonatomic, weak) IBOutlet UITextField * num2TextField;// 计算结果@property (nonatomic, weak) IBOutlet UILabel * resultLabel;- (IBAction) caculate;@end@implementation ViewController/* IBAction 1.相当于void 2.只有返回值类型,声明为IBAction的方法才有资格与storyboard连线 IBOutlet 他就是一个标识符,标示可与storyboard进行连线 *///计算- (IBAction) caculate{//  取出文本框的内容    NSString * num1Text = self.num1TextField.text;    NSString * num2Text = self.num2TextField.text;//  把字符串转换为int类型    NSInteger result = num1Text.intValue + num2Text.intValue;//  改变文本框的值    self.resultLabel.text = [NSString stringWithFormat:@"%ld", (long)result];//   退出键盘//    [self.num1TextField resignFirstResponder];//    [self.num2TextField resignFirstResponder];//    只要是自己或自己的子控件呼叫出来的键盘,都可以通过这个方法来退出键盘    [self.view endEditing:YES];}@end

加法计算器源码下载
http://download.csdn.net/download/yibo_oo/9401492

1 0
原创粉丝点击