计算器加减乘除(代码版)和大小写、首字母大写切换。


//计算器加减乘除(代码版)

#import "ViewController.h"


@interface ViewController ()


{

       //设置全局变量

       UITextField *_textField1;

       UITextField *_textField2;

       UITextField *_textField3;

}

@end


@implementation ViewController


- (void)viewDidLoad {

       [super viewDidLoad];

       //隐藏导航栏

       self.navigationController.navigationBarHidden=YES;

       //1个输入框

       _textField1=[[UITextField alloc]init];

       _textField1.frame=CGRectMake(0, 20, 80, 30);

       _textField1.backgroundColor=[UIColor yellowColor];

       [self.view addSubview:_textField1];

       

       //2个输入框

       _textField2=[[UITextField alloc]init];

       _textField2.frame=CGRectMake(100, 20, 80, 30);

       _textField2.backgroundColor=[UIColor redColor];

       [self.view addSubview:_textField2];

       

       //3个输入框

       _textField3=[[UITextField alloc]init];

       _textField3.frame=CGRectMake(200, 20, 80, 30);

       _textField3.backgroundColor=[UIColor blueColor];

       [self.view addSubview:_textField3];

       

       //加法绑定方法

       UIButton *jiaButton=[[UIButton alloc]init];

       jiaButton.frame=CGRectMake(0, 100, 50, 50);

       [jiaButton setTitle:@"加法" forState:UIControlStateNormal];

       [jiaButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

       [jiaButton addTarget:self action:@selector(addChange) forControlEvents:UIControlEventTouchUpInside];

       [self.view addSubview:jiaButton];

       //减法绑定方法

       UIButton *jianButton=[[UIButton alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];

       [jianButton setTitle:@"减法" forState:UIControlStateNormal];

       [jianButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

       [jianButton addTarget:self action:@selector(jianChange) forControlEvents:UIControlEventTouchUpInside];

       [self.view addSubview:jianButton];

       

       //乘法绑定方法

       UIButton *chenButton=[[UIButton alloc]initWithFrame:CGRectMake(200, 100, 50, 50)];

       [chenButton setTitle:@"乘法" forState:UIControlStateNormal];

       [chenButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

       [chenButton addTarget:self action:@selector(chenChange) forControlEvents:UIControlEventTouchUpInside];

       [self.view addSubview:chenButton];

       

       //除法绑定方法

       UIButton *chuButton=[[UIButton alloc]initWithFrame:CGRectMake(300, 100, 50, 50)];

       [chuButton setTitle:@"除法" forState:UIControlStateNormal];

       [chuButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

       [chuButton addTarget:self  action:@selector(chuChange) forControlEvents:UIControlEventTouchUpInside];

       [self.view addSubview:chuButton];

       

 

}


-(void)addChange{

       

       _textField3.text=[NSString stringWithFormat:@"%.1f",_textField1.text.floatValue+_textField2.text.floatValue];

}


-(void)jianChange{

       _textField3.text=[NSString stringWithFormat:@"%.1f",_textField1.text.floatValue-_textField2.text.floatValue];

 }


-(void)chenChange{

       _textField3.text=[NSString stringWithFormat:@"%.1f",_textField1.text.floatValue*_textField2.text.floatValue];

}



-(void)chuChange{

       _textField3.text=[NSString stringWithFormat:@"%.1f",_textField1.text.floatValue/_textField2.text.floatValue];

 }



转载于:https://my.oschina.net/u/2609104/blog/600393

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值