此bounty已结束。回答此问题可获得+300声望奖励。赏金宽限期21小时后结束jvdveuten正在寻找一个从一个有信誉的来源回答:developer.apple.com/documentation/uikit/…
developer.apple.com/documentation/uikit/…
我们该怎么用呢?它返回OP所说的,一个非常大的负数?
使用UIListContentConfiguration
时,如果您提供SF符号image
,系统将根据您的动态文字大小决定如何调整其大小。reservedLayoutSize
文档指出:“符号图像将在预定义的reservedLayoutSize
内居中,该reservedLayoutSize
根据内容大小类别进行缩放。”另请注意,Mac Catalyst的图像大小由您在“系统偏好设置”>“通用”>"侧边栏图标大小“中的设置决定。
在我的应用程序中,我想创建一个像照片应用程序一样的带有单元格的侧边栏-一个相册单元格有一张照片作为图像,而不是一个符号。要做到这一点,我需要知道使图像的大小,以确保它的大小与其他单元格中的符号相同,因为单元格的图像视图的大小是由您提供的图像的大小决定的。“非符号图像将使用等于所显示图像实际大小的reservedLayoutSize
。”
如何获得预定义的系统保留布局大小?UIListContentConfiguration.ImageProperties.standardDimension
听起来很有希望,但这只是一个通知系统使用其默认大小的常量,而不是暴露该大小-其值为-1.7976931348623157e+308。contentConfiguration.imageProperties.reservedLayoutSize
默认为CGSize.zero
,这意味着使用默认大小。那么,我们如何才能达到这个规模呢?
1条答案
按热度按时间mutmk8jj1#
根据文档正常使用:
您无法获取尺寸,但可以使用它来设置reservedLayoutSize的高度或宽度。然后,您必须根据当前文本大小调整图像的大小。这将考虑文本大小选项和辅助功能选项。这是正常的使用方法:
取实际宽度和高度:
如果你想获取图像的实际宽度和高度并从那里开始工作,你必须解决UIListContentConfiguration.ImageProperties.standardDimension的奇怪行为,我创建了这个类来布局自定义图标图像,就像SF Symbol布局一样。
诀窍是在contentConfiguration中设置一个“clear”SF Symbol作为图像,然后设置一个自定义图像。然后,自定义图像符合UIListContentView内的imageLayoutGuide提供的约束,以匹配布局。它使自定义图像居中。
也许也可以创建一个自己的contentConfiguration类,但现在这对我来说很有效。希望它足够优雅能解决你的问题。它甚至可以根据不同的文本大小或可访问性选项进行缩放。
下面是如何使用它:
下面是自定义类: