首页 > 编程语言 > 详细

SWIFT Button的基本用法

时间:2016-02-22 21:58:45      阅读:348      评论:0      收藏:0      [点我收藏+]
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        // Override point for customization after application launch.
        self.window!.backgroundColor = UIColor.whiteColor()
        self.window!.rootViewController = RootViewController()
        self.window!.makeKeyAndVisible()
        return true
    }


}
import UIKit

class RootViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //初始化button
        let btn = UIButton(type: UIButtonType.Custom)
        //尺寸
        btn.frame = CGRect(x: 100, y: 100, width: 100, height: 50)
        //背景颜色
        btn.backgroundColor = UIColor.redColor()
        //设置标题
        btn.setTitle("按钮", forState: UIControlState.Normal)
        //设置标题的颜色
        btn.setTitleColor(UIColor.greenColor(), forState: UIControlState.Normal)
        //添加点击事件
        btn.addTarget(self, action: "printSomeThing:", forControlEvents: UIControlEvents.TouchUpInside)
        //self.view加载子视图btn
        self.view.addSubview(btn)
    }
    //点击按钮执行的方法
    func printSomeThing(button:UIButton){
        print(button)
    }

}

 

SWIFT Button的基本用法

原文:http://www.cnblogs.com/lantu1989/p/5208117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!