美文网首页
2018-01-26 swift(xcode9.1)

2018-01-26 swift(xcode9.1)

作者: 张择端 | 来源:发表于2018-01-30 13:30 被阅读2次

    1.将日期选择器区域设置为中文(默认显示英文)      

    datapicker.locale = NSLocale(localeIdentifier: "zh_CN") as Locale

    2.

    let slider = heightNumber.value

            let i = Int(slider)

            height.text = "\(i)厘米"

    3.

    let segmentedControl = segmentedControl.selectedSegmentIndex==0 ? "高富帅" : "白富美"

    let switch = switch.isOn ? "有房" : "没房"

    根据日期选择器计算年龄

            let gregorian = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)

            let now = NSDate()

            let components = gregorian?.components([.year], from: age.date, to: now as Date, options: NSCalendar.Options(rawValue: 0))

            let ages = components?.year

            result.text = "姓名:\(name.text!),性别:\(segmentedControl),年龄:\(ages!)岁,身高:\(height.text!),\(switch)"

    4.修改键盘的return类型(xib或者纯代码),键盘消失

    name.delegate = self

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {

          textField.resignFirstResponder()

            return true

        }点击查看更多

    相关文章

      网友评论

          本文标题:2018-01-26 swift(xcode9.1)

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