美文网首页
映射,筛选,连接,猜数器

映射,筛选,连接,猜数器

作者: 天城一哥 | 来源:发表于2016-07-21 20:51 被阅读7次

    1.map :映射 (类型转换,如转换成字符串,作用在数组等集合上)
    filter:筛选 (作用在数组等集合上)
    reduce:连接 (不是一个数组了,只有一个值了)
    0 是初始值,不是第一个元素,如sum,就是从0开始加起 。
    连写的时候要注意!!!---->(),有时可能就是忘了()。
    字符串打印出来和数字看上去一样,都是数字。
    2.convert(转换)
    只建立一个带主函数的工程:OS X --->Application --->Command Line Tool
    font:字体
    bord:边界
    nav.divenedu.com png/jpg bm

    3.unwrapping : 打开,展开,
    unwarpping an optional value 打开一个可选的值,意思是要定义为变量
    一般就是label前的let 应该去掉。

    1. var label : UILabel!
      var textField:UITextField!
      var result = arc4random_uniform(100)
      //

      override func viewDidLoad() {
      super.viewDidLoad()

       label = UILabel()
       label.frame = CGRect(x: 80, y: 80, width: 100, height: 40)
       label.text = "猜一猜"
       label.backgroundColor = UIColor.redColor()
       label.textColor = UIColor.greenColor()
       label.font = UIFont.systemFontOfSize(28)
       label.textAlignment = .Center
       self.view.addSubview(label)
      

      let label1 = UILabel()
      label1.frame = CGRect(x: 50, y: 150, width: 40, height: 40)
      label1.text = "0"
      label1.backgroundColor = UIColor.redColor()
      label1.textColor = UIColor.greenColor()
      label1.font = UIFont.systemFontOfSize(28)
      label1.textAlignment = .Center
      self.view.addSubview(label1)

      let label2 = UILabel()
      label2.frame = CGRect(x: 100, y: 150, width: 40, height: 40)
      label2.text = "到"
      label2.backgroundColor = UIColor.redColor()
      label2.textColor = UIColor.greenColor()
      label2.font = UIFont.systemFontOfSize(28)
      label2.textAlignment = .Center
      self.view.addSubview(label2)

      let label3 = UILabel()
      label3.frame = CGRect(x: 150, y: 150, width: 60, height: 40)
      label3.text = "100"
      label3.backgroundColor = UIColor.redColor()
      label3.textColor = UIColor.greenColor()
      label3.font = UIFont.systemFontOfSize(28)
      label3.textAlignment = .Center
      self.view.addSubview(label3)

        textField = UITextField()
        
        textField.frame = CGRect(x: 100, y: 200, width: 100, height: 40)
        textField.textColor = UIColor.blueColor()
        textField.borderStyle = .RoundedRect
        textField.placeholder = "请输入数字"
        textField.keyboardType = .NumberPad
        self.view.addSubview(textField)
        
        let btn = UIButton(type: .System)
    // btn.setTitle("确定", forState: .Normal)
    

    // btn.setTitle("高亮", forState: .Highlighted)
    // btn.setTitle("选用", forState: .Selected)
    // btn.setTitle("禁用", forState: .Disabled)
    //

       let image = UIImage(named: "check")
        btn.setBackgroundImage(image, forState: .Normal)
        btn.frame = CGRect(x: 100, y: 300, width: 100, height: 100)
        btn.addTarget(self, action: #selector(didClick), forControlEvents:.TouchUpInside)
        
        
        self.view.addSubview(btn)
        
        
        
        
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    func didClick(){
        
        let number = UInt32(textField.text!)
    

    // //number自己输入的数字,result为系统生成的数字

        if result == number {
            label.text = "猜对了"
            result = arc4random_uniform(100)
        }else if result < number {
            label.text = "猜大了"
        }else{
            label.text = "猜小了"
        }
    

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    }

    相关文章

      网友评论

          本文标题:映射,筛选,连接,猜数器

          本文链接:https://www.haomeiwen.com/subject/gbnbjttx.html