• 使用Swift开发iOS项目、UI创建、方法调用


    //1、root控制器的创建

           var rootCtrl =RootViewController()

           var root:UINavigationController =UINavigationController(rootViewController: rootCtrl)

           self.window!.rootViewController = root



    //2、tab控制器的创建

            var tab =UITabBarController()

            tab.tabBar.barTintColor =UIColor.blackColor()

            tab.viewControllers = [oneCtrl, twoCtrl, threeCtrl, fourCtrl, fiveCtrl]

            self.window!.rootViewController = tab



    //3、声明属性

       var tableView:UITableView?



    //4、抽出TableView的创建方法

       func _initTableView(){

            //TableView的创建和设置

            self.tableView=UITableView(frame:CGRectMake(0,20,CGRectGetWidth(self.view.frame),CGRectGetHeight(self.view.frame)-64))

            self.tableView!.delegate =self

            self.tableView!.dataSource =self 

            self.tableView!.autoresizingMask = UIViewAutoresizing.FlexibleHeight |UIViewAutoresizing.FlexibleWidth

            self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier:"cell")

            self.view?

    .addSubview(self.tableView)

            self.tableView!.separatorColor =UIColor.cyanColor()

       }


        //dataSource 返回100个row

       func tableView(tableView:UITableView!, numberOfRowsInSection section: Int) ->Int

       {

              return 100

       }


        //cell的创建

       func tableView(tableView:UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) ->UITableViewCell!

        {

          let cell = tableView .dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)asUITableViewCell

               cell.textLabel.text =String(format:"%i", indexPath.row)

           return cell

        }



    UIKit

    // UILabel

       func createLabel() ->UILabel {

            var label:UILabel =UILabel(frame:CGRectMake(10,80,self.view.frame.size.width-20,50))

            label.backgroundColor =UIColor.clearColor()

            label.textAlignment =NSTextAlignment.Center

            label.textColor =UIColor.blackColor()

            label.font =UIFont.systemFontOfSize(25)

            label.text ="Hello Swift"

           return label

        }

        

        // UIView

       func createView() ->UIView {

           var orginY =CGRectGetMaxY(self.myLabel.frame) +10

           var myView:UIView =UIView(frame:CGRectMake(10, orginY,self.view.frame.size.width-20,30))

               myView.backgroundColor =UIColor.whiteColor()

           return myView;

        }

        

        // UIButton

       func createButton() ->UIButton {

           var orginY =CGRectGetMaxY(self.myView.frame) +10

           var button:UIButton =UIButton(frame:CGRectMake(10, orginY,self.view.frame.size.width-20,30))

            button.backgroundColor =UIColor.greenColor()

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

            button.titleLabel.font =UIFont.systemFontOfSize(12)

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

            button.tag =100

           return button

        }

        

        // UIImageView

       func createImageView() ->UIImageView {

           var orginY =CGRectGetMaxY(self.myButton.frame) +10

           var imageView:UIImageView =UIImageView(frame:CGRectMake((self.view.frame.size.width-100)/2, orginY,100,50))

           var image:UIImage =UIImage(named:"user")

               imageView.image = image

           return imageView

        }

        

        // Button target

       func tappedButton(sender:UIButton!) {

           println(sender.tag)

        }



      push 控制器的方法

    var listCtrl:UIViewController =UIViewController()

                listCtrl.title ="View Controller"

                listCtrl.view.backgroundColor =UIColor.redColor()

           self.navigationController.pushViewController(listCtrl, animated:true)


      pop

    self.navigationController.popViewControllerAnimated(true)

  • 相关阅读:
    sp_executesql介绍和使用
    jQuery中的 return false, e.preventDefault(), e.stopPropagation()的区别
    clearfix:after 清除css浮动
    paip.mysql 性能跟iops的以及硬盘缓存的关系
    paip.mysql 性能测试 报告 home right
    paip.mysql 性能测试by mysqlslap
    paip.java 架构师之路以及java高级技术
    paip. 提升性能---hibernate的缓存使用 总结
    paip. 解决php 以及 python 连接access无效的参数量。参数不足,期待是 1”的错误
    paip.解决access出现 -2147467259 无效的参数量
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10614295.html
  • Copyright © 2020-2023  润新知