//
// ViewController.swift
// CallTel
//
// Created by Romance on 17/3/31.
// Copyright (c) 2017年 jschrjkj. All rights reserved.
//
import UIKit
class ViewController: UIViewController,UITextFieldDelegate,UITextViewDelegate,UIAlertViewDelegate,UIActionSheetDelegate {
override func viewDidLoad() {
super.viewDidLoad()
var label=UILabel(frame: CGRect(x: 10, y: 20, width: 300, height: 100))
label.text="\(UIScreen.mainScreen().bounds.height)"
self.view.addSubview(label)
label.backgroundColor=UIColor.blackColor()
label.textColor=UIColor.whiteColor()
label.textAlignment=NSTextAlignment.Center
label.shadowColor=UIColor.grayColor()
label.shadowOffset=CGSizeMake( -5, 5)
label.font=UIFont(name: "Zapfino", size: 20)
label.adjustsFontSizeToFitWidth=true
label.numberOfLines=2
var button: UIButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton
button.setTitle("abcc", forState: UIControlState.Normal)
button.frame = CGRectMake(10,150,100,30)
self.view.addSubview(button)
button.addTarget(self, action: Selector("abc:"), forControlEvents: UIControlEvents.TouchUpInside)
var textfield = UITextField(frame: CGRect(x: 10, y: 200, width: 100, height: 30))
self.view.addSubview(textfield)
textfield.borderStyle = UITextBorderStyle.RoundedRect
textfield.placeholder = "username"
textfield.returnKeyType = UIReturnKeyType.Join
textfield.contentVerticalAlignment = UIControlContentVerticalAlignment.Center
textfield.delegate=self
var textview = UITextView(frame: CGRect(x: 150, y: 150, width: 100, height: 100))
textview.layer.borderColor = UIColor.blackColor().CGColor
textview.layer.borderWidth = 1
textview.dataDetectorTypes = UIDataDetectorTypes.All
textview.delegate = self
self.view.addSubview(textview)
var uiswitch = UISwitch(frame: CGRect(x: 150, y: 300, width: 150, height: 100))
uiswitch.on=true
uiswitch.addTarget(self, action: Selector("abcd:"), forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(uiswitch)
// Do any additional setup after loading the view, typically from a nib.
var items=["1","2","3"]
var segmented = UISegmentedControl(items: items)
segmented.frame = CGRect(x: 150, y: 400, width: 100, height: 30)
segmented.selectedSegmentIndex=items.count/2
segmented.tintColor=UIColor.redColor()
segmented.setTitle("Romance", forSegmentAtIndex: 2)
self.view.addSubview(segmented)
segmented.insertSegmentWithTitle("3", atIndex: 1, animated: true)
segmented.addTarget(self, action: Selector("abcde:"), forControlEvents: UIControlEvents.ValueChanged)
var imageview=UIImageView(frame: CGRect(x: 20, y: 300, width: 150, height: 100))
//imageview.image=UIImage(named: "1")
self.view.addSubview(imageview)
var images = [UIImage]()
/*for i in 1...9{
images.append( UIImage(named: "bomb0\(i)")!)
}
for i in 10...21{
images.append( UIImage(named: "bomb\(i)")!)
}*/
for i in 1...8{
images.append( UIImage(named: "Horse\(i)")!)
}
imageview.animationImages=images
imageview.animationDuration=1
imageview.startAnimating()
var progress = UIProgressView(progressViewStyle: UIProgressViewStyle.Default)
progress.center=self.view.center
progress.progress=0.5
self.view.addSubview(progress)
var slider = UISlider(frame: CGRect(x: 0, y: 0, width: 300, height: 50))
slider.maximumValue=1
slider.minimumValue=0
slider.value=0.5
slider.addTarget(self, action: Selector("abcdef:"), forControlEvents: UIControlEvents.ValueChanged)
slider.maximumValueImage=UIImage(named: "1")
slider.setThumbImage(UIImage(named: "1"), forState: UIControlState.Normal)
self.view.addSubview(slider)
/*var alterview=UIAlertView()
alterview.title="System"
alterview.message="You Want To Delete This Article?"
alterview.addButtonWithTitle("Yes")
alterview.addButtonWithTitle("NO")
alterview.cancelButtonIndex=0
alterview.delegate=self
alterview.show()
var acctionsheet=UIActionSheet()
acctionsheet.title="System"
acctionsheet.addButtonWithTitle("option1")
acctionsheet.addButtonWithTitle("option2")
acctionsheet.addButtonWithTitle("Cancel")
acctionsheet.cancelButtonIndex=2
acctionsheet.delegate=self
acctionsheet.showInView(self.view)*/
var steper=UIStepper()
steper.frame=CGRect(x: 200, y: 300, width: 200, height: 50)
steper.maximumValue=100
steper.minimumValue=0
steper.stepValue=1
steper.value=20
steper.continuous=true
steper.wraps=true
self.view.addSubview(steper)
steper.addTarget(self, action: Selector("steperclick:"), forControlEvents: UIControlEvents.ValueChanged)
var view1=self.view
var view2 = UIView(frame: CGRect(x: 0, y: 0, width: 480, height: 960))
view2.backgroundColor=UIColor.whiteColor()
var scrollview=UIScrollView()
scrollview.frame=self.view.bounds
imageview=UIImageView(image: UIImage(named: "timg"))
scrollview.contentSize=imageview.bounds.size
scrollview.addSubview(imageview)
view2.addSubview(scrollview)
scrollview.minimumZoomScale=0.1
scrollview.maximumZoomScale=3
scrollview.delegate=self
self.view=view2
var view3 = UIView(frame: CGRect(x: 0, y: 0, width: 480, height: 960))
view3.backgroundColor=UIColor.whiteColor()
let pages=3
let width=480
let heigh=960
scrollview=UIScrollView()
scrollview.frame=self.view.bounds
scrollview.contentSize=CGSizeMake(CGFloat(width*(pages)), CGFloat(heigh))
scrollview.pagingEnabled=true
scrollview.showsHorizontalScrollIndicator=false
scrollview.showsVerticalScrollIndicator=false
scrollview.scrollsToTop=false
for i in 0...pages{
var myview1 = myview(number: i+1)
myview1.view.frame=CGRectMake(CGFloat(width*i), CGFloat(0), CGFloat(width), CGFloat(heigh))
scrollview.addSubview(myview1.view)
}
view3.addSubview(scrollview)
self.view=view3
var view4 = UIView(frame: CGRect(x: 0, y: 0, width: 480, height: 960))
view4.backgroundColor=UIColor.whiteColor()
var datepicker=UIDatePicker(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
datepicker.datePickerMode = UIDatePickerMode.DateAndTime
datepicker.locale = NSLocale(localeIdentifier: "zh_CN")
view4.addSubview(datepicker)
datepicker.addTarget(self, action: Selector("click:"), forControlEvents: UIControlEvents.ValueChanged)
self.view=view4
}
func click(uidp:UIDatePicker)
{
println(uidp.date)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
for subview : AnyObject in scrollView.subviews{
if subview.isKindOfClass(UIImageView){
return subview as! UIView
}
}
return nil
}
func steperclick(steper: UIStepper) {
println(steper.value)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
println(actionSheet.buttonTitleAtIndex(buttonIndex))
}
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
println(alertView.buttonTitleAtIndex(buttonIndex))
}
func abcdef(uislider:UISlider)
{
println(uislider.value)
}
func abcde(segmented:UISegmentedControl)
{
println(segmented.titleForSegmentAtIndex(segmented.selectedSegmentIndex))
}
func abcd(uiswitch:UISwitch)
{
println(uiswitch.on)
}
func abc(button:UIButton)
{
println(button.titleLabel?.text)
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
textField.clearButtonMode = UITextFieldViewMode.WhileEditing
return true
}
func textViewDidChangeSelection(textView: UITextView) {
println(textView.selectedRange)
}
}