前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IOS 自定义UITableView单元格的高

IOS 自定义UITableView单元格的高

作者头像
用户5760343
发布2019-07-08 11:48:32
5040
发布2019-07-08 11:48:32
举报
文章被收录于专栏:sktjsktjsktj
 1 import UIKit
 2
 3 class ViewController:UIViewController,
 UITableViewDataSource, UITableViewDelegate {
 4
 5 override func viewDidLoad() {
 6 super.viewDidLoad()
 7 // Do any additional setup after loading the view,
 typically from a nib.
 8
 9 let screenRect = UIScreen.main.bounds
 10 let tableRect = CGRect(x:0, y:20, width:
 screenRect.size.width, height:screenRect.size.height - 20)
 11 let tableView = UITableView(frame:tableRect)
 12
 13 tableView.dataSource = self
 14 tableView.delegate = self
 15
 16 self.view.addSubview(tableView)
 17 }
 18
 19 func tableView(_ tableView:UITableView,
 heightForRowAt indexPath:IndexPath) -> CGFloat {
 20 if (indexPath as NSIndexPath).row % 2 == 0
 21 {
 22 return 104;
 23 }
 24 return 40;
 25 }
 26
 27 func tableView(_ tableView:UITableView,
 numberOfRowsInSection section:Int) -> Int{
 28 return 20
 29 }
 30
 31 func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) -> UITableViewCell {
 32
 33 let identifier = “reusedCell”
 34 var cell =
 tableView.dequeueReusableCell(withIdentifier:identifier)
 35
 36 if(cell == nil)
 37 {
 38 cell = UITableViewCell(style:
 UITableViewCellStyle.default, reuseIdentifier:identifier)
 39 }
 40 if (indexPath as NSIndexPath).row % 2 == 0
 41 {
 42 cell?.imageView?.image =
 UIImage(named:“picture.png”)
 43 }
 44 else
 45 {
 46 cell?.textLabel?.text = “每有会意,便欣然忘食!”
 47 }
 48
 49 return cell!
 50 }
 51 }
//UITableViewDelegate

image.png

image.png

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.06.02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档