标签:
//
// 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)
}
}
标签:
原文地址:http://www.cnblogs.com/happyEveryData/p/5610898.html