swift

swift写UI界面的

2018-09-13  本文已影响0人  ViewController_

//appdelegate里初始化独立的:

self.window?.rootViewController = UINavigationController(rootViewController: ViewController())

//导航上的左系统按钮:

self.navigationItem.leftBarButtonItem = UIBarButtonItem (barButtonSystemItem:        UIBarButtonSystemItem.camera, target: self, action: #selector(add(sender:)))

//自己写的导航上的按钮

let leftBtn = UIBarButtonItem(title: "back", style: .plain, target: self, action: #selector(leftButton))
        self.navigationItem.leftBarButtonItem = leftBtn

//添加图片:

前面是:var img : UIImage?

        img = UIImageView(frame: CGRect(x: 160, y: 100, width: 80, height: 80))

        img?.image = UIImage(named: "未选中的副本")

        self.view.addSubview(img!)

//文本框

前面是:var text : UITextField? = nil

text = UITextField(frame: CGRect(x: 50, y: 250, width: 300, height: 50))

        text?.backgroundColor = .green

        //提示文字

        text?.placeholder = "222"

        self.view.addSubview(text!)

//button

        btn = UIButton(frame: CGRect(x: 70, y: 380, width: 250, height: 50))

        btn?.backgroundColor = .blue

        btn?.setTitle("12345", for: .normal)

        self.view.addSubview(btn!)

//表格

tbv?.register(UITableViewCell.self, forCellReuseIdentifier: "SwiftCell");

let identify = "SwiftCell";

let cell = tableView.dequeueReusableCell(withIdentifier: identify, for: indexPath);

或者带副标题的:(里面是这个,上面多的注了)

let identify = "SwiftCell";

        var cell = tableView.dequeueReusableCell(withIdentifier: identify);

        if cell == nil {

            cell = UITableViewCell.init(style: UITableViewCellStyle.subtitle, reuseIdentifier:identify)

        }

。。。

左右侧滑的

/// 标题

        let titles = ["推荐","快讯", "深度", "实点对话", "行情分析"]

        //样式

        let style = YCTitleStyle()

        //可以滚动

        style.isScrollEnable = false

        // 所以的子控制器

        var childVcs = [UIViewController]()

        for _ in 0..<titles.count {

            let vc = UIViewController()

            vc.view.backgroundColor = UIColor.white

            childVcs.append(vc)

        }

        // pageView的frame

        let pageFrame = CGRect(x: 0, y: 65, width: view.bounds.width, height: view.bounds.height - 110)

        // 创建YCPageView,并且添加到控制器的view中

        let pageView = YCPageView(frame: pageFrame, titles: titles, childVcs: childVcs, parentVc: self, style : style)

        view.addSubview(pageView)

        tbv = UITableView(frame: CGRect(x: 0, y: 110, width: self.view.frame.size.width, height: self.view.frame.size.height-100), style: .plain)

        tbv?.delegate = self

        tbv?.dataSource = self

        tbv?.register(UITableViewCell.self, forCellReuseIdentifier: "SwiftCell");

        self.view.addSubview(tbv!)

上一篇下一篇

猜你喜欢

热点阅读