2018-01-26 swift(xcode9.1)

2018-01-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

    }点击查看更多

上一篇下一篇

猜你喜欢

热点阅读