映射,篩選,連接,猜數(shù)器

1.map :映射 (類型轉(zhuǎn)換,如轉(zhuǎn)換成字符串,作用在數(shù)組等集合上)
filter:篩選 (作用在數(shù)組等集合上)
reduce:連接 (不是一個(gè)數(shù)組了,只有一個(gè)值了)
0 是初始值,不是第一個(gè)元素,如sum,就是從0開(kāi)始加起 。
連寫(xiě)的時(shí)候要注意!??!---->(),有時(shí)可能就是忘了()。
字符串打印出來(lái)和數(shù)字看上去一樣,都是數(shù)字。
2.convert(轉(zhuǎn)換)
只建立一個(gè)帶主函數(shù)的工程:OS X --->Application --->Command Line Tool
font:字體
bord:邊界
nav.divenedu.com png/jpg bm

3.unwrapping : 打開(kāi),展開(kāi),
unwarpping an optional value 打開(kāi)一個(gè)可選的值,意思是要定義為變量
一般就是label前的let 應(yīng)該去掉。

  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 = "請(qǐng)輸入數(shù)字"
    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自己輸入的數(shù)字,result為系統(tǒng)生成的數(shù)字

    if result == number {
        label.text = "猜對(duì)了"
        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.
}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容