swift學習之UI控制項(一),swift學習ui控制項

來源:互聯網
上載者:User

swift學習之UI控制項(一),swift學習ui控制項

//

//  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 = "小豬飛!"

        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 = "肖"

        file.textColor = UIColor.blueColor()

        self.view.addSubview(file)

        

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

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

        

        button.setTitle("豬fjygjyy", forState:UIControlState.Normal)

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

        button.adjustsImageWhenHighlighted = false

                button.setBackgroundImage(UIImage(named: "0"), forState: .Normal)//設定背景

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

        self.view.addSubview(button)

        segmented ()

        /*

        建立一個文字框

        */

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

        textfield.borderStyle = UITextBorderStyle.RoundedRect//設定文字框為圓邊圓角

        textfield.placeholder = "yuebu"//設定提示句

        //        textfield.text = "hhhh"//設定預設值

        textfield.adjustsFontSizeToFitWidth = true //設定當超出文本時文字省略方式

        //        textfield.textAlignment = NSTextAlignment.Center//設定文字的水平對齊屬性

        //        textfield.contentVerticalAlignment = UIControlContentVerticalAlignment.Center//垂直對齊

        //簡寫

        //        textfield.returnKeyType = UIReturnKeyType.Go//設定鍵盤的返回鍵作用

        

        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)//不能改變UI,需在UI線程中操作

        println("我腎很好!")

        

        

    }

    

    func kaiguan (){

        

        var uiswitch : UISwitch

        uiswitch = UISwitch()

        uiswitch.center = CGPointMake(100, 50)

        uiswitch.on = true

        self.view.addSubview(uiswitch)

    }

    

    func segmented (){

        

        var items = ["張","蕭","阿","姨"]//,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)

        //幀動畫設定

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

        //設定變化時間

        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)

//        //幀動畫設定

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

//        //設定變化時間

//        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 = "是/否"

        alert.addButtonWithTitle("是")

        alert.addButtonWithTitle("否")

        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("不帥")

        }

        else{

            

            print("不帥!!!!")

            

        }

    }

    

 

}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.