OC中使用UI自定义控件实现计算器的设计(版本1简单的加减乘除,连加,连减,连除,连乘)

OC中使用UI自定义控件实现计算器的设计(版本1简单的加减乘除,连加,连减,连除,连乘)
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIApplicationDelegate>

{
    float _operator1;
    float _operator2;
    float _result;
}
@end
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UITextField * textFied1 = [[UITextField alloc]initWithFrame:CGRectMake(10, 30, 300 ,50)];
    textFied1.borderStyle = UITextBorderStyleLine;
    textFied1.backgroundColor = [UIColor redColor];
    [self.view addSubview:textFied1];
    textFied1.clearButtonMode = UITextFieldViewModeAlways;
    textFied1.tag = 007;
    
    
    
    UIButton * btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.Frame=CGRectMake(10, 90, 70, 70);
    btn1.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:btn1];
    [btn1 setTitle:@"7" forState:UIControlStateNormal];
    
    [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn1.tag = 7;
    
  
    UIButton * btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.Frame=CGRectMake(85, 90, 70, 70);
    btn2.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:btn2];
    [btn2 setTitle:@"8" forState:UIControlStateNormal];
    btn2.tag = 8;
    
    [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton * btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn3.Frame=CGRectMake(160, 90, 70, 70);
    btn3.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:btn3];
    [btn3 setTitle:@"9" forState:UIControlStateNormal];
    btn3.tag = 9;
    
   [btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton * btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn4.Frame=CGRectMake(235, 90, 70, 70);
    btn4.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:btn4];
    [btn4 setTi
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值