swift ui(一) uibutton

//

//  ViewController.swift

//  UIButtonTest_1

//

//  Created by lsr on 14-6-10.

//  Copyright (c) 2014 lsr. All rights reserved.

//


import UIKit


class ViewController:UIViewController  {

                            

    override func viewDidLoad() {

        super.viewDidLoad()

        initWithButton()

    }


    

    func initWithButton()

    {

        

        let button =UIButton(frame:CGRect(origin: CGPointMake(100.0, 110.0), size:CGSizeMake(150,50)))

        

        button.setTitle("OK", forState:UIControlState.Normal)

        

        button.setTitleColor(UIColor.blueColor(), forState:UIControlState.Normal)

        

        button.backgroundColor =UIColor.orangeColor()

        

        var image :UIImage = UIImage(named:"btn_login.png")

        

        button.setBackgroundImage(image, forState:UIControlState.Normal)

        

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

        

        self.view.addSubview(button)

        

    }


    

    func buttonClick(sender:UIButton!)

    {

        print("hello world")

        

    }


    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }



}

你可能感兴趣的:(swift)