//appdelegate里初始化獨(dú)立的:
self.window?.rootViewController = UINavigationController(rootViewController: ViewController())
//導(dǎo)航上的左系統(tǒng)按鈕:
self.navigationItem.leftBarButtonItem = UIBarButtonItem (barButtonSystemItem: ? ? ?? UIBarButtonSystemItem.camera, target: self, action: #selector(add(sender:)))
//自己寫(xiě)的導(dǎo)航上的按鈕
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);
或者帶副標(biāo)題的:(里面是這個(gè)围详,上面多的注了)
let identify = "SwiftCell";
? ? ? ? var cell = tableView.dequeueReusableCell(withIdentifier: identify);
? ? ? ? if cell == nil {
? ? ? ? ? ? cell = UITableViewCell.init(style: UITableViewCellStyle.subtitle, reuseIdentifier:identify)
? ? ? ? }
左右側(cè)滑的
/// 標(biāo)題
? ? ? ? let titles = ["推薦","快訊", "深度", "實(shí)點(diǎn)對(duì)話(huà)", "行情分析"]
? ? ? ? //樣式
? ? ? ? let style = YCTitleStyle()
? ? ? ? //可以滾動(dòng)
? ? ? ? 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)
? ? ? ? // 創(chuàng)建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!)