为什么在修改其帧高度时仅接受非零值?

发布于 2025-01-20 13:24:15 字数 1202 浏览 5 评论 0原文

谁能告诉我为什么UaiteView的tableheaderview属性仅接受非零值?

我正在尝试修改我的uitableview的tableheaderview用于缩小上限的属性的高度值。

以下是我接近的方式。

设置uitableview中表格的高度属性值为0实际上会删除上部边距

但是在应用以下代码时,没有任何更改。

//UIView has the tableView property for its one of sub views
tableView.tableHeaderView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 0, height: 0)))

我在网上搜索了这一点,发现了一些 从苹果参考 似乎TableHeaderview属性仅接受其修改的非零值。 因此,我只是将高度设置的值设置为cgfloat.leastnormalmagnitude,它只是有效的。

tableView.tableHeaderView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 0, height: CGFloat.leastNormalMagnitude)))

我很好奇的是,我仍然无法承受为什么零值和最小值值有所不同。 设置帧高度值不应该为0实际删除屏幕上的Uiview吗?

Can anyone tell me why UITableView's tableHeaderView property only accepts non zero value?

I'm trying to modify the height value of my UITableView's tableHeaderView property for narrowing upper margin.

Below is the way I approached.

Setting the height property value of tableHeaderView in UITableView as 0 would actually remove the upper margin

However, nothing has changed when applying the code as below.

//UIView has the tableView property for its one of sub views
tableView.tableHeaderView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 0, height: 0)))

I searched online about this and found some
explanation from apple reference
enter image description here
It seems like tableHeaderView property only accepts non zero value for its modification.
So I just set the value for height setting as CGFloat.leastNormalMagnitude and it just worked.

tableView.tableHeaderView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 0, height: CGFloat.leastNormalMagnitude)))

The point I'm curious about is that I still cannot undertstand why zero value and leastNormalMagnitude value make difference.
Shouldn't setting frame height value as 0 actually remove the UIView on screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不离久伴 2025-01-27 13:24:15

从我在Apple doc 中看到的:

将视图分配给此属性时,将该视图的高度设置为非零值。

没有为什么。就是这样。

From what I see in Apple doc :

When assigning a view to this property, set the height of that view to a nonzero value.

There is no why. It is just like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文