上記の画像の様にTableViewのCell内にimageView,Label,Labelを
配置しAutoLayoutを設定しております。(imageViewを選択後Add New Constraintsで左の数値を0に設定)
この状態でBuildすると下記の様に表示されます。(AutoLayoutが適応されている)
上記の画像の状態でCellをタップすると下記の画像の様に画像がずれてしまい、Labelに画像が重なってしまいます。
ソースは下記の様に実装しております。
どなたか解決方法をご教示いただけますと幸いです。
よろしくお願いいたします。
import UIKit class CustomTableViewCell: UITableViewCell { @IBOutlet weak var articleImage: UIImageView! @IBOutlet weak var articleDateTime: UILabel! @IBOutlet weak var articleTitle: UILabel! override func awakeFromNib() { super.awakeFromNib() } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } func setCell(imageNames: String, articleDateTimes: String, articleTitles: String) { articleImage.image = UIImage(named: imageNames) articleDateTime.text = articleDateTimes articleTitle.text = articleTitles } }
import UIKit var refreshControl:UIRefreshControl! class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet var tableView: UITableView! let home = Home() override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return home.imageNames.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! CustomTableViewCell cell.setCell(imageNames: home.imageNames[indexPath.row], articleDateTimes: home.articleDateTimes[indexPath.row], articleTitles: home.articleTitles[indexPath.row]) return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { print(home.imageNames[indexPath.row]) } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/08 09:15