• 代码构建视图


       一下代码全部在 didFinishLaunchingWithOptions 初始化事件:

      //设置window窗体颜色

            self.window = UIWindow(frame: UIScreen.mainScreen().bounds);

            self.window?.backgroundColor=UIColor.redColor();

            self.window?.makeKeyAndVisible();

            

            // 绑定视图控制器,可以将初始化数据在 制定的ViewControler执行。

            self.window?.rootViewController = ViewController()

            

            // 新建视图

            var rootView=UIView(frame: CGRect(x: 0, y: 0, 400, height: 400));

            rootView.backgroundColor = UIColor.whiteColor();

            self.window?.addSubview(rootView);

                

            // 新增lable

            var lable1 = UILabel(frame: CGRect(x: 100,y: 200, 100,height: 50))

            lable1.text="Hello";

            lable1.textColor = UIColor.blackColor();

            lable1.tag = 2 ;

            rootView.addSubview(lable1);

            

            //新增button

            var button1 = UIButton(frame: CGRect(x: 100,y: 100, 100,height: 50));

            button1.setTitle("ClickMe", forState: UIControlState.Normal);

            button1.backgroundColor = UIColor.blackColor();

            

            // 代码绑定事件

            button1.addTarget(self, action: "button1Click:", forControlEvents: UIControlEvents.TouchUpInside);

            

            rootView.addSubview(button1);

            

            // 约束 相对位置 约束条件

            //rootView.addConstraint(NSLayoutConstraint(item: <#AnyObject#>, attribute: <#NSLayoutAttribute#>, relatedBy: <#NSLayoutRelation#>, toItem: <#AnyObject?#>, attribute: <#NSLayoutAttribute#>, multiplier: <#CGFloat#>, constant: <#CGFloat#>)

            

            return true

  • 相关阅读:
    jq隐藏页面的一行(循环隐藏10行)
    Button的OnClientClick()事件不起作用?
    Infopath自定义表单实现列表字段联动
    SharePoint 2013的传出电子邮件设置
    codeforces Looksery Cup 2015 D. Haar Features
    codeforces Looksery Cup 2015 H Degenerate Matrix
    poj3321 Apple Tree
    poj1990 MooFest
    poj2155 Matrix
    hdu1556 Color the ball
  • 原文地址:https://www.cnblogs.com/pengzhaov/p/4454532.html
Copyright © 2020-2023  润新知