swift写UI界面的
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift写UI界面的相关的知识,希望对你有一定的参考价值。
参考技术A //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!)
以上是关于swift写UI界面的的主要内容,如果未能解决你的问题,请参考以下文章