zoukankan      html  css  js  c++  java
  • swift基础语法之控件使用02

    //第一个控制器:显示基础控件

    import UIKit


    class ViewController: UIViewController {

        

        var label: UILabel = UILabel()

        var button: UIButton = UIButton()

        var imageView: UIImageView = UIImageView()

        

    //    var label: UILabel?

    //    var button: UIButton?

    //    var imageView: UIImageView?

        

        override func viewDidLoad() {

            super.viewDidLoad()

            // Do any additional setup after loading the view, typically from a nib.

            /**

            UILabel

            */

            self.label = UILabel(frame: CGRectMake(10, 50, 100, 30))

            self.label.text = "hehe"

            self.label.backgroundColor = UIColor.greenColor()

            self.label.textAlignment = NSTextAlignment.Center

            self.view.addSubview(self.label)

            /**

            UIButton

            */

            self.button = UIButton(frame: CGRectMake(50, 100, 100, 30))

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

            self.button.backgroundColor = UIColor.redColor()

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

            self.view.addSubview(self.button)

            /**

            UIImageView

            */

            self.imageView = UIImageView(frame: CGRectMake(100, 150, 100, 100))

            self.imageView.image = UIImage(named:"user")

            self.view.addSubview(self.imageView)

        }

        

        func bntclik(button:UIButton){

            var oneVC = ViewControllerOne()

            var oneNA: UINavigationController = UINavigationController(rootViewController: oneVC)

            self.presentViewController(oneNA, animated:true, completion: nil)

        

            println("button")

            

        }

        override func didReceiveMemoryWarning() {

            super.didReceiveMemoryWarning()

            // Dispose of any resources that can be recreated.

        }



    }



    //第二个控制器:显示表格视图


    import UIKit


    class ViewControllerOne: UIViewController,UITableViewDataSource,UITableViewDelegate {

        var tableView: UITableView = UITableView()

        var dataArray: NSArray = []


        override func viewDidLoad() {

            super.viewDidLoad()


            // Do any additional setup after loading the view.

            self.view.backgroundColor = UIColor.whiteColor()

            self.dataArray = ["1","2","3","4","5","6"]

            /**

            UITableView

            */

            self.tableView = UITableView(frame: CGRectMake(0, 0,CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)), style: UITableViewStyle(rawValue: 0)!)

            self.tableView.delegate = self

            self.tableView.dataSource = self

            self.view.addSubview(self.tableView)

        }

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

        {

            return self.dataArray.count

        }

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

        {

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


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

            cell.textLabel.text = self.dataArray[indexPath.row] as NSString;

            return cell


            

        }

        override func didReceiveMemoryWarning() {

            super.didReceiveMemoryWarning()

            // Dispose of any resources that can be recreated.

        }

        


    }

  • 相关阅读:
    Compression algorithm (deflate)
    tcpip数据包编码解析(chunk and gzip)_space of Jialy_百度空间
    What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
    gzip压缩算法: gzip 所使用压缩算法的基本原理
    Decompressing a GZip Stream with Zlib
    Frequently Asked Questions about zlib
    how to decompress gzip stream with zlib
    自己动手写web服务器四(web服务器是如何通过压缩数据,web服务器的gzip模块的实现)
    What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
    C语言抓http gzip包并解压 失败 C/C++ ChinaUnix.net
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7289383.html
Copyright © 2011-2022 走看看