UI第一个出画面的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds] ] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
   
    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)];
    self.window.backgroundColor = [UIColor grayColor];
    [self.window addSubview:aView];
    
    UITextField *firstNumber = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, 50, 30)];
    firstNumber.borderStyle = UITextBorderStyleRoundedRect;//输入框的样式
    firstNumber.keyboardType =  UIKeyboardTypeNumberPad;//弹出键盘样式
    firstNumber.tag = 100;
    [self.window addSubview:firstNumber];
    [firstNumber release];
    
    UILabel *plusLable = [[UILabel alloc] initWithFrame:CGRectMake(80, 40, 20, 30)];
    plusLable.text = @"+"; //所显示的文本内容
    plusLable.textAlignment = NSTextAlignmentCenter; //所显示的文本内容位置
    [self.window addSubview:plusLable];
    [plusLable release];
    
    UITextField *secondNumber = [[UITextField alloc] initWithFrame:CGRectMake(110, 40, 50, 30)];
    secondNumber.borderStyle = UITextBorderStyleRoundedRect;
    secondNumber.keyboardType = UIKeyboardTypeNumberPad;
    secondNumber.tag = 200;
    [self.window addSubview:secondNumber];
    [secondNumber release];
    
    UILabel *resultLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 40, 30, 30)];
    resultLabel.textAlignment = NSTextAlignmentLeft;
    resultLabel.tag = 300;
    [self.window addSubview:resultLabel];
    [resultLabel release];
    
    UIButton *caulatorButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    caulatorButton.frame = CGRectMake(170, 40, 50, 30);
    [caulatorButton setTitle:@" = " forState:UIControlStateNormal];
    [caulatorButton addTarget:self action:@selector(plus:) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:caulatorButton];
    
    
    return YES;
}
- (void)plus:(UIButton *)button
{
    UITextField *firstTf = (UITextField *)[self.window viewWithTag:100];
    UITextField *secondTf = (UITextField *)[self.window viewWithTag:200];
    NSString *firstNumberStr = firstTf.text;
    NSString *secondNumberStr = secondTf.text;
    int result = firstNumberStr.intValue + secondNumberStr.intValue;
    UILabel *resultLable = (UILabel *)[self.window viewWithTag:300];
    resultLable.text = [NSString stringWithFormat:@"%d",result];
    
}
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值