zoukankan      html  css  js  c++  java
  • Swift计算器

    //

    //  ViewController.swift

    //  FristSwift

    //

    //  Created by Evan on 16/6/23.

    //  Copyright © 2016年 Evan. All rights reserved.

    //

    import UIKit

    let SCREEN_WIDTH = UIScreen.mainScreen().bounds.size.width;

    let SCREEN_HEIGHT = UIScreen.mainScreen().bounds.size.height;

    class ViewController: UIViewController

    {

        let textFile1:UITextField = UITextField(frame:CGRectZero)

        let plusLable:UILabel = UILabel(frame:CGRectZero)

        let textFile2:UITextField = UITextField(frame:CGRectZero)

        let equalLable:UILabel = UILabel(frame: CGRectZero)

        let resultLable:UILabel = UILabel(frame:CGRectZero)

        

        let button:UIButton = UIButton(frame:CGRectZero)

       

       override func viewDidLoad()

        {

            super.viewDidLoad()

            

            self.addContent();

            

            self.contentContraints();

        }

        

        func addContent()

        {

            textFile1.backgroundColor = UIColor.redColor()

            textFile1.keyboardType = UIKeyboardType.NumberPad

            self.view.addSubview(textFile1)

            

            plusLable.text = "+"

            plusLable.textColor = UIColor.greenColor()

            self.view.addSubview(plusLable)

            

            textFile2.backgroundColor = UIColor.redColor()

            textFile2.keyboardType = UIKeyboardType.NumberPad

            self.view.addSubview(textFile2)

            

            equalLable.text = "="

            equalLable.textColor = UIColor.greenColor()

            self.view.addSubview(equalLable)

            

            resultLable.backgroundColor = UIColor.redColor()

            self.view.addSubview(resultLable)

            

            button.backgroundColor = UIColor.redColor()

            button.setTitle("计算", forState:UIControlState.Normal)

            button.addTarget(self,action:Selector("buttonClick"),forControlEvents:UIControlEvents.TouchUpInside)

            self.view.addSubview(button)

        }

        

        func buttonClick()

        {

            let resultNum = (textFile1.text! as NSString).intValue + (textFile2.text! as NSString).intValue

            let resultStr = String(resultNum)

            resultLable.text = resultStr

            print(resultStr)

        }

          func contentContraints()

        {

            textFile1.frame = CGRectMake(10, 30, 50, 50)

            plusLable.frame = CGRectMake(65, 40, 20, 20)

            textFile2.frame = CGRectMake(80, 30, 50, 50)

            equalLable.frame = CGRectMake(135, 40, 20, 20)

            resultLable.frame = CGRectMake(155, 30, 50, 50)

            button.frame = CGRectMake(50, 100, 100, 30)

        }

    }

  • 相关阅读:
    FCK常用Js,获取FCK内容,统计FCK字数,向FCK写入指定代码
    asp 点击链接 下载图片文件
    使用微软的 Visual Studio International Pack 1.0 进行网站简体与繁体的互转和得到汉字、拼音、笔画
    mysql alter 语句用法,添加、修改、删除字段等
    C#指定窗口显示位置的方法
    Soukey采集软件源码
    [转](收藏)《博客园精华集》分类索引
    YUI CSS Foundation讲座 博客文库 博客园
    sql group by 和having
    sql 多表查询
  • 原文地址:https://www.cnblogs.com/happyEveryData/p/5610898.html
Copyright © 2011-2022 走看看