Coder Social home page Coder Social logo

ios-002_lovefinder's Introduction

示例002、相亲(控件介绍)

  • 课程地址(幕课网-使用 Swift 开发第二章)

  • 代码地址(Github)

  • 关键代码

    • 绑定相关视图控件

        @IBOutlet weak var name: UITextField! 
        ...
      


    • 点击下一项,关闭键盘

        选中控件,右侧面板中 Return Key 选择 Next
      

        // ViewController 实现 UITextFieldDelegate 协议,完成方法
        func textFieldShouldReturn(textField: UITextField) -> Bool {
            textField.resignFirstResponder()
            return true
        }
      


    • UISlider 控件的事件

        @IBAction func heightChanged(sender: AnyObject) {
            
            height.text = "\(Int(heightNum.value))cm"
            
        }
      


    • 点击确定,提交数据事件

        @IBAction func btnOk(sender: AnyObject) {
            
            // 性别
            let gender = sex.selectedSegmentIndex == 0 ? "高富帅" : sex.selectedSegmentIndex == 1 ? "白富美" : "人妖"
            
            // 年龄
            let gregorian = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
            let now = NSDate()
            let components = gregorian?.components(NSCalendarUnit.Year, fromDate: birthday.date, toDate: now, options: NSCalendarOptions(rawValue: 0))
            let age = components?.year
            
            // 房产
            let hasHouseText = hasHouse.on ? "有房" : "没放"
            
            
            result.text = "\(name.text!), \(age!)岁, \(gender)性, 身高\(height.text!)cm, \(hasHouseText), 求交往!"
            
        }
      

ios-002_lovefinder's People

Contributors

itcatface avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.