swift寫UI界面的

//appdelegate里初始化獨立的:

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


//導(dǎo)航上的左系統(tǒng)按鈕:

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

//自己寫的導(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)題的:(里面是這個,上面多的注了)

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 = ["推薦","快訊", "深度", "實點對話", "行情分析"]

? ? ? ? //樣式

? ? ? ? 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)


? ? ? ? // 創(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!)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容