芥 -- swift

import UIKit

class ScoreWriteVC: UIViewController {

typealias blockScore = (String,String,String)->()
var jumpScore:blockScore?

var tf1:UITextField!
var tf2:UITextField!
var tf3:UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    
    self.navigationItem.title = "分数录入"
    
    view.backgroundColor = UIColor.white
    
    let lab1 = UILabel(frame: CGRect(x: 30, y: 200, width:60 , height: 60))
    view.addSubview(lab1)
    lab1.text = "语文"
    
    let lab2 = UILabel(frame: CGRect(x: 30, y: 200+lab1.frame.height+10, width:60 , height: 60))
    view.addSubview(lab2)
    lab2.text = "数学"
    
    let lab3 = UILabel(frame: CGRect(x: 30, y: 200+lab1.frame.height+10+lab2.frame.height+10, width:60 , height: 60))
    view.addSubview(lab3)
    lab3.text = "英语"
    
    tf1 = UITextField(frame: CGRect(x: 50+lab1.frame.width+5, y: 200, width: UIScreen.main.bounds.width-(50+lab1.frame.width+5)-10, height: 60))
    view.addSubview(tf1)
    tf1.placeholder = "请输入分数"
    tf1.borderStyle = .roundedRect
    
    tf2 = UITextField(frame: CGRect(x: 50+lab1.frame.width+5, y: 200+tf1.frame.height+10, width: UIScreen.main.bounds.width-(50+lab1.frame.width+5)-10, height: 60))
    view.addSubview(tf2)
    tf2.placeholder = "请输入分数"
    tf2.borderStyle = .roundedRect
    
    tf3 = UITextField(frame: CGRect(x: 50+lab1.frame.width+5, y: 200+tf1.frame.height+10+tf2.frame.height+10, width: UIScreen.main.bounds.width-(50+lab1.frame.width+5)-10, height: 60))
    view.addSubview(tf3)
    tf3.placeholder = "请输入分数"
    tf3.borderStyle = .roundedRect
    
    let btn1 = UIButton(frame: CGRect(x: (UIScreen.main.bounds.width-100)/2-60, y: 200+lab1.frame.height+10+lab2.frame.height+10+lab3.frame.height+30, width: 100, height: 80))
    view.addSubview(btn1)
    btn1.setTitle("保存", for: .normal)
    btn1.addTarget(self, action: #selector(save), for: .touchUpInside)
    btn1.setTitleColor(UIColor.red, for: .normal)
    
    let btn2 = UIButton(frame: CGRect(x: (UIScreen.main.bounds.width-100)/2+60, y: 200+lab1.frame.height+10+lab2.frame.height+10+lab3.frame.height+30, width: 100, height: 80))
    view.addSubview(btn2)
    btn2.setTitle("返回", for: .normal)
    btn2.addTarget(self, action: #selector(back), for: .touchUpInside)
    btn2.setTitleColor(UIColor.red, for: .normal)
}

@objc func save() {
    
    self.jumpScore!(tf1.text!,tf2.text!,tf3.text!)
    
    self.navigationController?.popViewController(animated: true)
}

@objc func back() {
    
    self.navigationController?.popViewController(animated: true)
}

}

猜你喜欢

转载自blog.csdn.net/qq_22049111/article/details/84348637