Swift 自定義表格

class AppDelegate: UIResponder, UIApplicationDelegate {

? ? var window: UIWindow?

? ? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

? ? ? ? let vc = ViewController()

? ? ? ? let nvc = UINavigationController(rootViewController: vc)

? ? ? ? self.window?.rootViewController = nvc;



? ? ? ? return true

? ? }






class MyTableViewCell: UITableViewCell {

? ? var image1 = UIImageView()

? ? var time = UILabel()

? ? var name = UILabel()

? ? var names = UILabel()

? ? override init(style: UITableViewCellStyle, reuseIdentifier: String?) {

? ? ? ? super.init(style: style, reuseIdentifier: reuseIdentifier)

? ? ? ? self.contentView.addSubview(image1)

? ? ? ? self.contentView.addSubview(time)

? ? ? ? self.contentView.addSubview(name)

? ? ? ? self.contentView.addSubview(names)

? ? ? ? name.font = UIFont.systemFont(ofSize: 14)

? ? ? ? names.font = UIFont.systemFont(ofSize: 8)

? ? ? ? time.font = UIFont.systemFont(ofSize: 8)

? ? ? ? image1.frame = CGRect(x: 10, y: 10, width: 30, height: 30);

? ? ? ? name.frame = CGRect(x: 60, y: 10, width:UIScreen.main.bounds.size.width - 160, height: 50);

? ? ? ? names.frame = CGRect(x: 60, y: 70, width:UIScreen.main.bounds.size.width - 160, height: 50);

? ? ? ? time.frame = CGRect(x:UIScreen.main.bounds.size.width - 140, y: 0, width: 100, height: 20)

? ? }


? ? required init?(coder aDecoder: NSCoder) {

? ? ? ? fatalError("init(coder:) has not been implemented")

? ? }

}


class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

? ? var tabel = UITableView();


? ? override func viewDidLoad() {

? ? ? ? super.viewDidLoad()

? ? ? ? self.view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)

? ? ? ? self.title = "asdj"

? ? ? ? tabel = UITableView.init(frame:UIScreen.main.bounds, style: .plain)

? ? ? ? tabel.delegate = self

? ? ? ? tabel.dataSource = self

? ? ? ? tabel.rowHeight = 80

? ? ? ? tabel.register(UINib.init(nibName: "MyTableViewCell", bundle: nil) , forCellReuseIdentifier:? "cellid")

? ? ? ? self.view.addSubview(tabel)


? ? }

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

? ? ? ? return 3;

? ? }

? ? func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

? ? ? ? var cell:MyTableViewCell? = tableView.dequeueReusableCell(withIdentifier: "") as? MyTableViewCell

? ? ? ? if cell == nil {

? ? ? ? ? ? cell = MyTableViewCell(style: .subtitle, reuseIdentifier: "cellid")

? ? ? ? }

? ? ? ? cell?.image1.image = UIImage(named: "1")

? ? ? ? cell?.names.text = "不是假的不放假as百度金礦發(fā)布阿斯加德加多寶房價開始";

? ? ? ? cell?.name.text = "sjshdjkskd";

? ? ? ? cell?.time.text = "201730-4743"

? ? ? ? return cell!

? ? }

? ? func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

? ? ? ? let one = OneViewController()

? ? ? ? //跳轉(zhuǎn)

? ? ? ? self.navigationController?.pushViewController(one, animated: true)


? ? }


}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容