gpt4 book ai didi

ios - 页脚 View 不会粘在 UITableView 的底部,而是与表格重叠(自动布局问题)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:00:42 25 4
gpt4 key购买 nike

出于某种原因,我的页脚与表格重叠,而不是充当页脚,直至底部。这很可能是一个自动布局

var coreView = UIView() //This is the footer
var postBody = UILabel() //This is the label, which will determine the height of the footer.

let nib = UINib(nibName: "MessagesTableViewCell", bundle: nil)
let

nibSimple = UINib(nibName: "SimpleMessagesTableViewCell", bundle: nil)
self.tableView.registerNib(nib, forCellReuseIdentifier: "MessagesTableViewCell")
self.tableView.registerNib(nibSimple, forCellReuseIdentifier: "SimpleMessagesTableViewCell")
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 100.0
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
self.tableView.separatorColor = UIColor(hex: 0xf5f5f5)
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
self.tableView.clipsToBounds = true
self.tableView.allowsMultipleSelection = false
self.tableView.keyboardDismissMode = .OnDrag


coreView.backgroundColor = UIColor.yellowColor()

//Create Label and add it to the footer
postBody.text = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog."
postBody.font = UIFont(name: "Roboto-Regular", size: 16.0)
postBody.lineBreakMode = .ByWordWrapping
postBody.numberOfLines = 0
postBody.backgroundColor = FlatLime()
coreView.addSubview(postBody)

//Enable constraints for footer and label
postBody.translatesAutoresizingMaskIntoConstraints = false
coreView.translatesAutoresizingMaskIntoConstraints = false

//Add constraints to the footer and post body
let postBodyLeadingConstraint = NSLayoutConstraint(item: postBody, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: coreView, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0)
postBodyLeadingConstraint.active = true

let postBodyTrailingConstraint = NSLayoutConstraint(item: postBody, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: coreView, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: 0)
postBodyTrailingConstraint.active = true

let postBodyTopConstraint = NSLayoutConstraint(item: postBody, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: coreView, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0)
postBodyTopConstraint.active = true

let postBodyBottomConstraint = NSLayoutConstraint(item: postBody, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: coreView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
postBodyBottomConstraint.active = true

postBody.preferredMaxLayoutWidth = screenWidth
self.tableView.tableHeaderView = UIView(frame: CGRectZero)
self.tableView.tableFooterView = coreView

如您所见,自动布局用于确定页脚 View 的高度(基于标签的高度)。然而,这是结果。页脚与表格“重叠”,即使我将它设置为最后一行的页脚 View 。

另外:有谁知道为什么coreView右边有一个空白区域?

footer overlaps table

最佳答案

为什么不尝试将 UITableViewStyle 更改为 Group,我认为它会起作用。

关于ios - 页脚 View 不会粘在 UITableView 的底部,而是与表格重叠(自动布局问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37062669/

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