• SWIFT Button的基本用法


    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,  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)
        }
    
    }
  • 相关阅读:
    程序员修炼之道阅读笔记2
    程序员修炼之道阅读笔记1
    软件体系架构的质量属性
    计算贴现率相关问题
    以《淘宝网》为例,描绘质量属性的六个常见属性场景
    第十四周总结
    软件需求模式阅读笔记
    第十三周总结
    第十二周总结
    重大技术需求进度报告六
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5208117.html
Copyright © 2020-2023  润新知