Dating Artifact Record Swift1.2

Source: Internet
Author: User
Tags hasproperty

This simple app is written in swfit1.2, the main focus is: 1. Click the Keyboard return button to exit the keyboard. 2. Delivery of individual control values.

Storyboard Interface Design:

View Code:

1 Import UIKit2 3 class Viewcontroller:uiviewcontroller, uitextfielddelegate{4 5 @IBOutlet weak var name:uitextfield!6 @IBOutlet weak var gender:uisegmentedcontrol!7 @IBOutlet weak var birthday:uidatepicker!8 @IBOutlet weak var heightnumber:uislider!9 @IBOutlet weak var height:uilabel!Ten @IBOutlet weak var hasproperty:uiswitch! One @IBOutlet weak var result:uitextview! A      - override func Viewdidload () { - super.viewdidload () the name.delegate = self//Click Return to exit the keyboard -     } - override func didreceivememorywarning () { - super.didreceivememorywarning () + //Dispose of any resources, can be recreated. -     } +  A @IBAction func heightchanged (sender:anyobject) { at var slider = sender as! UISlider - var i = int (slider.value)//float converted to int - Slider.value = Float (i)//conversion Operation - height.text = "\ (i) cm"//change the value of the label with the slider -     } -  in @IBAction func oktapped (sender:anyobject) { - Let gendertext = gender.selectedsegmentindex==0? "Gao Fu Shuai": "White rich beauty" to Let Gregorian = Nscalendar (Calendaridentifier:nscalendaridentifiergregorian) + Let now = NSDate () - birthday.maximumdate = NSDate ()//To prevent negative age the Let components = Gregorian?. Components (Nscalendarunit.calendarunityear, FromDate:birthday.date, Todate:now, options:nscalendaroptions (0))// Calculate Age *          $ Let -age = components!. year//Get AgePanax Notoginseng Let haspropertytext = Hasproperty.on? "Room": "No Room"//switch Value data -          the result.text = "\ (name.text), \ (age), \ (gendertext), height \ (height.text!), \ (haspropertytext), Seek intercourse!" +          A     } the      + //uitextfileddelegate, click Return to make the keyboard exit - func Textfieldshouldreturn (Textfield:uitextfield), bool{ $ Textfield.resignfirstresponder () $ return True -     } -}

It is important to note in this code that, because of the swift language change, it needs to be added after the assignment or display of age and Height.text! , or you will get an error.

Operating effect:

Dating Artifact Record Swift1.2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.