gpt4 book ai didi

swift - UITableview Cell 无法在 iPad 屏幕尺寸上正确调整大小

转载 作者:行者123 更新时间:2023-11-28 14:56:12 25 4
gpt4 key购买 nike

在 iPad 上运行我的应用程序时,显示会被拉伸(stretch),并且 UITableview Cell 的宽度和高度不会自动调整为 iPad 的屏幕尺寸。我尝试了所有可能的约束,但它看起来仍然不对

the correct appearance on iPhone:

the wrong appearance on iPad:

the cell structure:

the UItableview:

View Controller 代码:

    //
// ViewController.swift
// FinalProject
//
// Created by Matan Levi on 7.11.2017.
// Copyright © 2017 Matan Levi. All rights reserved.
//

import UIKit


class ViewController: UIViewController, UITabBarDelegate, UITableViewDelegate, UITableViewDataSource {


@IBOutlet weak var firstTableViewOutlet: UITableView!



var srt = ""
var nowPlaying : [Movie] = []
var srtNew = ""
var onAirNow : [TvShow] = []
var getNowPlayingMoviesBool = false
var getOnAirTvShows = false



override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

title = "WatchIt"

ApiHandler.shared.getMoviesGeners()
ApiHandler.shared.getTvShowsGeneres()
ApiHandler.shared.getNowPlayingMovies{
DispatchQueue.main.async {
self.getNowPlayingMoviesBool = true; self.firstTableViewOutlet.reloadData()
}
}

ApiHandler.shared.getTvShowsAiringNow {
DispatchQueue.main.async {
self.getOnAirTvShows = true; self.firstTableViewOutlet.reloadData()
}
}

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let firstCell = tableView.dequeueReusableCell(withIdentifier: "firstCell") as! FirstTableViewCell
uiMakeShadowDesign(viewForShadowDesign: firstCell.mainViewShadowOutletNew)
uiMakeDesign(viewForDesign: firstCell.mainViewOutletNew)
switch indexPath.row {
case 0:
if getNowPlayingMoviesBool == true
{
firstCell.mainLabel.text = "In Theaters"
firstCell.imageViewOne.makeImageFromString(imageString: AppManager.shared.nowPlayingMovies[0].posterPath)
firstCell.imageViewTwo.makeImageFromString(imageString: AppManager.shared.nowPlayingMovies[1].posterPath)
for i in 0...8
{
self.srt += "\(AppManager.shared.nowPlayingMovies[i].title),"
}
firstCell.names.text = srt
}
case 1:
if getOnAirTvShows == true
{
firstCell.mainLabel.text = "On Air"
firstCell.imageViewOne.makeImageFromString(imageString: AppManager.shared.onAirNow[0].posterPath)
firstCell.imageViewTwo.makeImageFromString(imageString: AppManager.shared.onAirNow[1].posterPath)
for i in 0...8
{
self.srtNew += "\(AppManager.shared.onAirNow[i].name),"
}
firstCell.names.text = srtNew
}

default:
break
}


return firstCell

}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}




func uiMakeDesign(viewForDesign : UIView)
{
viewForDesign.layer.cornerRadius = 20
viewForDesign.layer.cornerRadius = 20
viewForDesign.layer.masksToBounds = true
}

func uiMakeShadowDesign(viewForShadowDesign : UIView)
{
viewForShadowDesign.layer.shadowColor = UIColor.black.cgColor
viewForShadowDesign.layer.shadowOpacity = 1
viewForShadowDesign.layer.shadowOffset = CGSize.zero
viewForShadowDesign.layer.shadowRadius = 10
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let selectedIndexPath = firstTableViewOutlet.indexPathForSelectedRow

{
if let inTheatereOrOnAirNowViewController = segue.destination as? InTheatersOrOnAirNowViewController
{
inTheatereOrOnAirNowViewController.movieOrTvShow = selectedIndexPath.row
}
}
}


}

最佳答案

选择您的 View (高度)约束。在属性检查器中查看约束,然后单击 +(加号),然后单击高度选项卡并将其更改为(常规到紧凑),然后单击添加变体。

之后根据你给wC hC(Constraint)。

它会起作用。

Screenshot

关于swift - UITableview Cell 无法在 iPad 屏幕尺寸上正确调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49300983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com