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)系作者
  • 序言:七十年代末蔗喂,一起剝皮案震驚了整個濱河市耕姊,隨后出現(xiàn)的幾起案子蚓耽,更是在濱河造成了極大的恐慌,老刑警劉巖频祝,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件泌参,死亡現(xiàn)場離奇詭異,居然都是意外死亡常空,警方通過查閱死者的電腦和手機沽一,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來漓糙,“玉大人铣缠,你說我怎么就攤上這事。” “怎么了蝗蛙?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵蝇庭,是天一觀的道長。 經(jīng)常有香客問我捡硅,道長哮内,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任壮韭,我火速辦了婚禮北发,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘喷屋。我一直安慰自己琳拨,他們只是感情好,可當我...
    茶點故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布屯曹。 她就那樣靜靜地躺著狱庇,像睡著了一般。 火紅的嫁衣襯著肌膚如雪是牢。 梳的紋絲不亂的頭發(fā)上僵井,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天陕截,我揣著相機與錄音驳棱,去河邊找鬼。 笑死农曲,一個胖子當著我的面吹牛社搅,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播乳规,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼形葬,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了暮的?” 一聲冷哼從身側(cè)響起笙以,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎冻辩,沒想到半個月后猖腕,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡恨闪,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年倘感,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片咙咽。...
    茶點故事閱讀 39,722評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡老玛,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情蜡豹,我是刑警寧澤麸粮,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站余素,受9級特大地震影響豹休,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜桨吊,卻給世界環(huán)境...
    茶點故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一威根、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧视乐,春花似錦洛搀、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至伸刃,卻和暖如春谎砾,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背捧颅。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工景图, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人碉哑。 一個月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓挚币,卻偏偏與公主長得像,于是被迫代替她去往敵國和親扣典。 傳聞我的和親對象是個殘疾皇子妆毕,可洞房花燭夜當晚...
    茶點故事閱讀 44,614評論 2 353

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