TableViewのCellに画面の横幅いっぱいでCellのした50くらいを残して表示させたいです。
何をやっても、Cellの高さいっぱいに表示されてどうにもなりません。教えて下さい。
swift
1class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{ 2 3 4 let menus : [String] = ["ご飯1","ご飯2","ご飯3","ご飯4","ご飯5","タご飯6","ご飯7","ご飯8","ご飯9"] 5 6 let keys : [String] = ["あ","い","う","え","お","か","き","く","け","こ","さ","し"] 7 8 let menuImages = ["pizza.JPG","guril.JPG","asupara.JPG","","","","","","","",""] 9 10 var testImages:[UIImage] = [] 11 12 13 // ステータスバーの高さ 14 let statusBarHeight = UIApplication.shared.statusBarFrame.height 15 16 override func viewDidLoad() { 17 super.viewDidLoad() 18 19 // UITableView を作成 20 let tableView = UITableView() 21 22 23 // サイズと位置調整 24 tableView.frame = CGRect( 25 x: 0, 26 y: statusBarHeight , 27 width: self.view.frame.width, 28 height: self.view.frame.height - statusBarHeight 29 ) 30 31 // Delegate設定 32 tableView.delegate = self 33 34 35 // DataSource設定 36 tableView.dataSource = self 37 38 // 画面に UITableView を追加 39 self.view.addSubview(tableView) 40 41 //for menuImage in menuImages { 42 // testImages.append(UIImage(named: menuImage)!) 43 //} 44 45 } 46 47 override func didReceiveMemoryWarning() { 48 super.didReceiveMemoryWarning() 49 } 50 51 // MARK: - UITableViewDataSource 52 53 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 54 // セルを作る 55 56 let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell") 57 cell.textLabel?.text = menus[indexPath.row] 58 cell.detailTextLabel?.text = keys[indexPath.row] 59 cell.detailTextLabel?.textColor = UIColor.gray 60 cell.imageView?.image = UIImage(named: menuImages[indexPath.row]) 61 _ = cell.imageView?.image?.resize(size: CGSize(width: 100, height: 200)) 62 63 64 return cell 65 } 66 67 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 68 // セルの数を設定 69 return menus.count 70 } 71 72 73 74} 75
回答2件
あなたの回答
tips
プレビュー