UI control for swift Learning (1): ui control for swift Learning

Source: Internet
Author: User

UI control for swift Learning (1): ui control for swift Learning

//

// ViewController. swift

// Test

//

// Created by chuangqu on 15/7/23.

// Copyright (c) 2015 theway. All rights reserved.

//

 

Import UIKit

 

Class ViewController: UIViewController {

 

Override func viewDidLoad (){

Super. viewDidLoad ()

Var lable = UILabel (frame: CGRectMake (120, 20,100, 20 ))

Lable. text = "pig Fei! "

Lable. textColor = UIColor. blueColor ()

Lable. backgroundColor = UIColor. brownColor ()

Lable. textAlignment = NSTextAlignment. Center

Lable. shadowColor = UIColor. grayColor ()

Lable. shadowOffset = CGSizeMake (-5, 5)

Lable. font = UIFont (name: "zapfino", size: 20)

Self. view. addSubview (lable)

Var file = UITextField (frame: CGRectMake (120, 80,100, 20 ))

File. text = "Xiao"

File. textColor = UIColor. blueColor ()

Self. view. addSubview (file)

Var button: UIButton = UIButton. buttonWithType (UIButtonType. System)! UIButton;

Button. frame = CGRectMake (120,150,100, 80)

Button. setTitle ("pig fjygjyy", forState: UIControlState. Normal)

// Button. setImage (UIImage (named: "0"), forState:. Normal)

Button. adjustsImageWhenHighlighted = false

Button. setBackgroundImage (UIImage (named: "0"), forState:. Normal) // set the background

Button. addTarget (self, action: Selector ("test"), forControlEvents: UIControlEvents. TouchUpInside)

Self. view. addSubview (button)

Segmented ()

/*

Create a text box

*/

Var textfield = UITextField (frame: CGRectMake (10, 20,100, 20 ))

Textfield. borderStyle = UITextBorderStyle. RoundedRect // you can specify the rounded corner in the text box.

Textfield. placeholder = "yuebu" // sets the prompt statement.

// Textfield. text = "hhhh" // set the default value

Textfield. adjustsFontSizeToFitWidth = true // You can omit the text when the text exceeds the limit.

// Textfield. textAlignment = NSTextAlignment. Center // you can specify the horizontal alignment attribute of text.

// Textfield. contentVerticalAlignment = uicontrolcontentverticalignment. Center // Vertical Alignment

// Shorthand

// Textfield. returnKeyType = UIReturnKeyType. Go // set the keyboard's return key

Textfield. contentVerticalAlignment =. Center

Textfield. clearButtonMode =. WhileEditing

// Textfield. clearButtonMode = UITextFieldViewMode. UnlessEditing

// Textfield. clearButtonMode =. UnlessEditing

Self. view. addSubview (textfield)

// Kaiguan ()

Img ()

Animation ()

// Progess ()

// Test ()

// Do any additional setup after loading the view, typically from a nib.

}

Override func didReceiveMemoryWarning (){

Super. didReceiveMemoryWarning ()

// Dispose of any resources that can be recreated.

}

Func test (){

// Button. setTitle ("", forState: UIControlState. Normal) // The UI cannot be changed and must be operated in the UI thread.

Println ("My kidney is good! ")

}

Func kaiguan (){

Var uiswitch: UISwitch

Uiswitch = UISwitch ()

Uiswitch. center = CGPointMake (100, 50)

Uiswitch. on = true

Self. view. addSubview (uiswitch)

}

Func segmented (){

Var items = ["Zhang", "Xiao", "A", ""] //, UIImage (named: "icon")]

Var seg = UISegmentedControl (items: items)

Seg. center = self. view. center

Seg. selectedSegmentIndex = 1

Self. view. addSubview (seg)

}

Func img (){

Var imge = UIImageView (image: UIImage (named: "3 "))

Imge. frame = CGRectMake (90,350,200,200)

Self. view. addSubview (imge)

}

Var imageview: UIImageView!

Func animation (){

Imageview = UIImageView ()

Imageview. frame = CGRectMake (90,350,200,200)

// Frame Animation settings

// Imageview. animationImages = [UIImage (named: "0"), UIImage (named: "3")]

// Set the Change Time

Imageview. animationDuration = 0.5

Self. view. addSubview (imageview)

}

Override func viewWillAppear (animated: Bool ){

Super. viewWillAppear (animated)

Imageview. startAnimating ()

}

 

Override func viewWillDisappear (animated: Bool ){

Super. viewWillDisappear (animated)

Imageview. stopAnimating ()

}

// Override func DidLoad (){

// Super. viewDidLoad ()

// Imageview = UIImageView ()

// Imageview. frame = CGRectMake (90,350,200,200)

//// Frame Animation settings

// Imageview. animationImages = [UIImage (named: "3"), UIImage (named: "3"), UIImage (named: "3")]

//// Set the Change Time

// Imageview. animationDuration = 0.5

// Self. view. addSubview (imageview)

//

//}

Func progess (){

Var progres = UIProgressView (progressViewStyle: UIProgressViewStyle. Default)

Progres. center = self. view. center

Progres. progress = 0.5

Progres. setProgress (0.8, animated: true)

Self. view. addSubview (progres)

Var alert = UIAlertView ()

Alert. frame = CGRectMake (200,150,100,100)

Alert. title = ""

Alert. message = "yes/no"

Alert. addButtonWithTitle ("yes ")

Alert. addButtonWithTitle ("no ")

Alert. cancelButtonIndex = 0

Alert. delegate = self

Alert. show ()

 

Hhh (alert, clickedButtonAlertIndex: alert. cancelButtonIndex)

}

Func hhh (alert: UIAlertView, clickedButtonAlertIndex button: Int ){

If button = alert. cancelButtonIndex {

Print ("not handsome ")

}

Else {

Print ("not handsome !!!! ")

}

}

 

}

 

Related Article

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.