*当前xcode开发版本为6.4
IOS开发说明:
ViewController拖拽跳转到新的viewcontroller,松开拖拉的时候会有一个黑色的弹出框,每一个选项的含义:
push:一定要放在Navigation Controller中,如果没有放在Navigation Controller中程序会挂掉
mode:
custom:是客户化的选项
1.获取和设置控件属性值
编辑框
var value:String? = myEdit.text
myEdit.text = "设置编辑框的值"
myEdit.resignFirstResponder() //编辑框输入完之后隐藏输入法
图片
myImage.image = UIImage(named:String("图片名"))
myImage.image=UIImage(data:NSData(contentsOfURL:NSURL(string:"http://192.168.1.136:8080/HHH.png")))
单选按钮
let gender = MySegmentControl.selecterSegmentIndex//获取当前被选中的角标
滚动条
//对于该控件一般是对你他的改动时间进行监听
@IBAction func heightChange(sender: AnyObject) {
var slider = sender as! UISlider //将sender强转为UIslide
var i = Int(slider.value)
slider.value = Float(i) //设置slider的值
//heightnum.text = "\(i)厘米"
}
UISwitch(根据on 或者 off判断)
let isTrue = mySwitch.on ? true:false
UIDataPicker
let chooseTime = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)//先初始化出一个NSCalendar对象
let nowtime = NSDate() //获取当前时间
let muchYear = chooseTime!.components(NSCalendarUnit.CalendarUnitYear, fromDate: birthday.date, toDate: nowtime, options: NSCalendarOptions(0)//得到两个时间的差值,第一个参数是差值类型(需要计算的差值年、月、日)
let age = muchYear.year //获取两个时间年差值的值
UIPickerView
该控件绑定数据的时候要实现两个接口,分别是UIPickerViewDataSource和UIPickerViewDelegate
//重写UIPickerViewDataSource返回的是picker的静态信息
extension ViewController: UIPickerViewDataSource{
//用来返回pickerView有几项,这里只有一项你本身列表,所以返回1
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{
return 1
}
//返回该picker一项里面有几个华东选项
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
return beauties.count
}
}
//重写UIPickerViewDelegate是为了给picker绑定那个数据deauties
extension ViewController: UIPickerViewDelegate{
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!{
return beauties[row]
}
}
最后在UIPickerView的UIViewController的ViewDidLoad声明自定义接口
myPicker.dataSource = self
myPicker.delegate = self
2.开发中常会重写的方法
//该方法是只要touch了屏幕就会调用该方法,除了touch输入法时不会调用,所以该方法常常会被用于点击输入法以为的位置隐藏输入法
override func touchesEnded(touches: Set, withEvent event: UIEvent) {
myEdit.resignFirstResponder()//隐藏myEdit弹出的输入法
}
//该方法是与UITextField(即EditText)相关,当UITextField获取焦点弹出输入法时,输入法的右下角有一个可以自定义的按钮(return key),该方法就是对该按钮功能的重写
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
//ViewController之间传值
//当发生Segue即页面跳转的时候会调用到该方法
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "GoToGallery" {
let pickerIndex = beautyPicker.selectedRowInComponent(0) //获得picker当前被选中的Index,参数“0”是第几个picker,因为这里只有一个Picker所以是0
var imageName:String? = String(pickerIndex+1)
let vc = segue.destinationViewController as! GalleryViewController
vc.imageName = imageName!
}
}